bool ShouldPlatformReturn();
.h에서 함수를 정의할때 앞에 형식을 붙일시 해당 자료형을 반환하게 된다
if (DistanceMoved > MoveDistance)
{
FString Name = GetName();
float OverValue = DistanceMoved - MoveDistance;
UE_LOG(LogTemp, Display, TEXT("%s => OverValue = %f"), *Name, OverValue);
FVector MovedDirection = PlatformVelocity.GetSafeNormal();
StartLocation = StartLocation + MovedDirection * MoveDistance;
SetActorLocation(StartLocation);
PlatformVelocity *= -1;
}
bool AMovingPlatform::ShouldPlatformReturn()
{
return DistanceMoved > MoveDistance;
}
기존에 사용되던 조건문에서 조건을 가져와서 함수화 시켜준다
if (ShouldPlatformReturn())
그러면 bool을 return받아서 if문 안쪽에서 조건 검사를 함수로 할 수 있게 된다
이때 함수로 가져오면서 함수 내부 변수값들이 손실되기에 이를 해결해야 한다
CurrentLocation
은
void AMovingPlatform::MovePlatform(float DeltaTime)
의 내부에서 생성된 지역 변수이기에, 타 변수에서 가져올 수 없다

그렇기에 이를 다시 가져와 준다
bool AMovingPlatform::ShouldPlatformReturn()
{
float DistanceMoved = FVector::Dist(StartLocation, GetActorLocation());
return DistanceMoved > MoveDistance;
}
GetDistanceMoved()정의하기
bool AMovingPlatform::ShouldPlatformReturn()
{
return GetDistanceMoved() > MoveDistance;
}
float AMovingPlatform::GetDistanceMoved()
{
return FVector::Dist(StartLocation, GetActorLocation());
}
강좌에서는 이렇게 함수화를 하던데, 취향차이라고 생각한다
'공부 > 언리얼 엔진' 카테고리의 다른 글
| 언리얼 엔진 공부 42 - FRotator (1) | 2025.08.06 |
|---|---|
| 언리얼 엔진 공부 41 - const 멤버 함수(Const Member Functions) (1) | 2025.08.06 |
| 언리얼 엔진 공부 39 - 멤버 함수(Member Functions) (1) | 2025.08.04 |
| 언리얼 엔진 공부 37 - 출력 로그에 기록하기(Writing To The Output Log) (2) | 2025.08.04 |
| 언리얼 엔진 공부 36 - 게임 모드(Game mode) (4) | 2025.08.04 |