개요
언리얼에서 블루프린트 연동을 위한 리플렉션 시스템에서 'UFUNCTION' 매크로의 기능에 대해서 정리해보았다.
UFUNCTION
메소드에 붙는 리플렉션 매크로입니다.
인자값을 통해 용도에 맞게 활용할 수 있다.
만약 인자값이 없다면 언리얼 리플렉션 시스템에 메소드를 등록만 하고 실제 블루프린트에서 활용은 불가능하다.
지정자들 중 가장 많이 사용되는 BlueprintCallable, BlueprintPure, BlueprintImplementableEvent를 알아보자.
BlueprintCallable
UFUNCTION에 해당 지정자를 사용하면 블루프린트의 이벤트 그래프에서 호출 가능한 함수로 만들어준다.
호출 가능한 함수는 실행 핀이 존재하는 노드로 만들어 주는 것이라고 이해하면 된다.
다음과 같이 함수를 선언하면
UCLASS(Blueprintable,BlueprintType)
class STUDYPROJECT_API ATestItem : public AActor
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void ResetActorPosition();
};
다음과 같이 ResetActorPosition()을 블루프린트에서 호출 가능 노드로 만들 수 있다.
BlueprintPure
UFUNCTION에 해당 지정자를 사용하면 이벤트 그래프에서 Getter 역할을 수행할 수 있게 해준다.
호출가능한 핀은 없고 Return Value값만 사용가능한 노드라고 이해하면 된다.
다음과 같이 함수를 선언하면
UCLASS(Blueprintable,BlueprintType)
class STUDYPROJECT_API ATestItem : public AActor
{
GENERATED_BODY()
UStaticMeshComponent* StaticMeshComp;
public:
UFUNCTION(BlueprintCallable)
void ResetActorPosition();
UFUNCTION(BlueprintPure)
UStaticMeshComponent* GetStaticMeshComp();
};
다음과 같이 이벤트 그래프에 노출된다.
BlueprintImplementableEvent
UFUNCTION에 해당 지정자를 사용하면 함수 선언만 C++에 있고 실제 함수 정의는 Blueprint에서 하도록 한다.
이때 함수 정의가 C++에 존재하면 안된다.
사용 예시로는 언리얼 DamageFramework에서 Receive[DamageEvent]Damage()가 있다.
다음과 같이 함수를 선언하면
UCLASS(Blueprintable,BlueprintType)
class STUDYPROJECT_API ATestItem : public AActor
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintImplementableEvent)
void OnItemPickup();
};
다음과 같이 이벤트 노드처럼 해당 함수를 구현할 수 있다.
해당 이벤트는 C++에서 OnItemPickup()을 호출하면 실행된다.
Reference
https://dev.epicgames.com/documentation/ko-kr/unreal-engine/ufunctions-in-unreal-engine
'Unreal' 카테고리의 다른 글
[Unreal] State Machine (0) | 2025.01.21 |
---|---|
[Unreal C++]1주차 강의 정리 (0) | 2025.01.20 |
[Unreal C++] Damage Framework (0) | 2025.01.12 |
[Unreal] Collision 채널 (1) | 2025.01.08 |
[Unreal C++] 객체 Class 타입 비교하기 (1) | 2025.01.07 |