I tried using reflection to loop through the properties, and found out it returns the wrong type for members of FGuid
. The correct type should be uint32
but calling GetCPPType()
returns int32
.
To reproduce, create a Actor
UCLASS()
class DEBUGFPS_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
UPROPERTY(EditAnywhere, Category = Test)
FGuid TestGuid;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
In the constructor, use this code
AMyActor::AMyActor()
{
for (TFieldIterator<UProperty> it{ GetClass()}; it; ++it)
{
auto prop = *it;
auto name = prop->GetName();
auto type = prop->GetCPPType();
UE_LOG(LogTemp, Warning, TEXT("Class Prop: %s\t type: %s"), *name, *type);
if (auto structProp = CastField<FStructProperty>(prop))
{
for (TFieldIterator<UProperty> structPropIt{ structProp->Struct }; structPropIt; ++structPropIt)
{
UE_LOG(LogTemp, Warning, TEXT("Name: %s, Type: %s"), *structPropIt->GetName(), *structPropIt->GetCPPType());
}
}
}
}
Output
[2022.10.09-08.12.58:537][ 0]LogTemp: Warning: Class Prop: TestGuid type: FGuid
[2022.10.09-08.13.31:754][ 0]LogTemp: Warning: Name: A, Type: int32
[2022.10.09-08.13.34:709][ 0]LogTemp: Warning: Name: B, Type: int32
[2022.10.09-08.14.34:309][ 0]LogTemp: Warning: Name: C, Type: int32
[2022.10.09-08.14.38:587][ 0]LogTemp: Warning: Name: D, Type: int32
Guid’s definition in Engine\Source\Runtime\Core\Public\Misc\Guid.h
....
public:
/** Holds the first component. */
uint32 A;
/** Holds the second component. */
uint32 B;
/** Holds the third component. */
uint32 C;
/** Holds the fourth component. */
uint32 D;
};