Randomly stumbled upon this question while browsing the wiki for more information on the property system.
The quote simply means that it’s possible to call UObject::GetClass()
on any given UObject
instance, but not on any F
instance because there simply is no class from which all structs derive, unlike the UObject
class for all objects.
Example:
// Assigned somewhere in your code
AActor MyActor;
// Get a pointer to the AMyActorClass UClass instance at runtime.
UClass *MyActorClass = AMyActorClass::StaticClass();
// For the sake of this example, the following code SHOULD work (not sure right now,
// haven't tested), even though there is a method UObject::IsA() which does the same.
if( UClass::FindCommonBase(MyActor->GetClass(), MyActorClass) == MyActorClass ) {
// Print a debug message for 10 seconds on screen. For more info, google the function.
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Yellow,
// This is just the text we want to display.
FString(TEXT("My actor is an instance of AMyActorClass"))
);
}
// This will not work because the `GetClass()` method is defined nowhere within the Unreal Engine:
FColor::Yellow->GetClass();
The above code should attempt to find the first common base between the two given classes, namely the class of the given AActor
instance and a custom class AMyActorClass
. If the provided actor indeed is an instance of AMyActorClass
the check should return true and print an onscreen message. If it is not, nothing should happen.
However, the last line will result in an error because the symbol GetClass
is undefined. It is neither defined in FColor
nor in any of its parent structs - in fact, FColor
does not derive any struct at all. I found a nice little complementary article on garbage collection here. It also explains the difference between structs and objects in UE4.
I’m by far not proficient with the Unreal Property System and frankly I’m a bit confused about the FTypeName::StaticClass
part - usually structs or unreflected classes are prefixed with F meaning they are more or less out of scope of the property system. Thus FTypeName::StaticClass
, as for my understanding, usually is an undefined symbol as well.
Once you have access to a UClass
, you can use TFieldIterator It(MyClass)
to iterate over the reflected fields of your class. This would be useful for custom serialization where you want all reflected properties to be somehow saved to a file, for example.