본문 바로가기
Unreal

WorldContextObject을 인자로 요구하는 C++함수을 블루프린트 노드로 만들기

by myroad 2023. 8. 17.

C++코드에서 UGameplayStatics::GetPlayerPawn( )함수는 첫 번째 인자로 WorldContextObject을 인자로 요구한다. 따라서 보통 GetWorld()함수을 통해 인자을 입력해 준다.

APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);

하지만 블루프린트의 GetPlayerPawn노드 에서는 WorldContextObject 인자를 요구하지 않는다. 그 이유는 meta 키워드을 통해서 WorldContextObject을 설정해 주기 때문이다.

 

아래 코드는 블루프린트의 GetPlayerPawn 노드에 대한 C++ 선언이다.

보면 알겠지만 WorldContextObject을 meta 키워드을 통해 설정하고 있는 것을 볼 수 있다. 즉 메타 데이터 설정을 통해 자동으로 WorldContextObject가 설정되게 구현한 것이다. 따라서 블루프린트의 GetPlayerPawn노드에서는  WorldContextObject을 인자로 줄 필요가 없다.

UFUNCTION(BlueprintPure, Category="Game", 
          meta=(WorldContext="WorldContextObject", 
                UnsafeDuringActorConstruction="true"))
static class APawn* GetPlayerPawn(const UObject* WorldContextObject, 
                                  int32 PlayerIndex);

따라서 만약 C++함수을 블루프린트 노드로 만들어야 하는 상황이고 해당 함수가 WorldContextObject을 인자로 요구한다면 meta 키워드을 통해 자동으로 설정되게 구현 할 수 있다.

 

참고 - https://romeroblueprints.blogspot.com/2021/04/understanding-worldcontextobject.html