Unreal
언리얼의 리플렉션 기능을 이용하여 클래스나 구조체의 정보 얻기
myroad
2023. 8. 14. 14:16
아래의 코드에서 TFieldIterator나 UProperty을 사용하기 위해서는 위에 정의된 헤더 파일들을 기억하자.
#include "UObject/UnrealType.h"
#include "UObject/UnrealTypePrivate.h"
void AccessVariableNames()
{
FMyStructure MyStructureInstance;
const UStruct* Struct = MyStructureInstance.StaticStruct();
for (TFieldIterator<UProperty> PropIt(Struct); PropIt; ++PropIt)
{
UProperty* Property = *PropIt;
FString PropertyName = Property->GetName();
FString PropertyNameCPP = Property->GetNameCPP();
UE_LOG(LogTemp, Warning, TEXT("Property Name: %s (CPP: %s)"), *PropertyName, *PropertyNameCPP);
}
}