Unreal Engine/[Inflearn_rookiss] UE5 Lyra 분석
1. Reflection, TSubclassOf 기본 개념
헛둘이
2024. 9. 26. 03:53
Reflection
클래스의 메타 데이터를 가져오는 등 엔진에서 각 클래스 자체의 정보에 접근하기 위해 사용하는 기술
- C#에선 기본적으로 내장되어 있으나 C++에서는 제공하지 않으므로, generated.h 헤더파일과 GENERATED_BODY 내부적으로 많은 매크로들을 사용하여 구현되어 있습니다.
- UCLASS를 붙이면 해당 클래스의 메타데이터를 읽어오도록 합니다.
FFieldClass* FField::StaticClass()
{
static FFieldClass StaticFieldClass(TEXT("FField"), FField::StaticClassCastFlagsPrivate(), FField::StaticClassCastFlags(), nullptr, &FField::Construct);
return &StaticFieldClass;
}
클래스명::StaticClass를 따라가보면 이렇게 구성되어 있는 것을 알 수 있습니다.
그리고 FFieldClass를 따라가보면 아래와 같이 나옵니다.
class FFieldClass
{
UE_NONCOPYABLE(FFieldClass);
/** Name of this field class */
FName Name;
/** Unique Id of this field class (for casting) */
uint64 Id;
/** Cast flags used for casting to other classes */
uint64 CastFlags;
/** Class flags */
EClassFlags ClassFlags;
/** Super of this class */
FFieldClass* SuperClass;
/** Default instance of this class */
FField* DefaultObject;
/** Pointer to a function that can construct an instance of this class */
FField* (*ConstructFn)(const FFieldVariant&, const FName&, EObjectFlags);
/** Counter for generating runtime unique names */
FThreadSafeCounter UnqiueNameIndexCounter;
.
.
.
FieldClass에서 리플렉션을 통해 읽어온 메타데이터를 저장하고 이 데이터에 접근하여 엔진에서 필요한 기능들을 제공합니다.
TSubclassOf
- 서브 클래스, 파생 클래스라고 이야기하는, 일반적으로는 이 클래스를 상속받은 클래스만 넣을 수 있는 타입