Now I could get the property of the actor through unreal reflection.
But some of them are custom type or complicated type(not simple type), I want to parse these complicated property recursively to get their inner property which is simple type.
I have some problems with getting the child property of the property, the code is following:
I found that if Property refers to a complex type like FVector, the code will not be able to enter the for loop below.So I think there is problem with getting the child property
FString GetBasicTypePropertyValue(FProperty* Property, void* ValueAddress)
{
if (Property->IsA(FIntProperty::StaticClass()))
{
return FString::FromInt(*(int32*)ValueAddress);
}
else if (Property->IsA(FFloatProperty::StaticClass()))
{
return FString::SanitizeFloat(*(float*)ValueAddress);
}
else if (Property->IsA(FBoolProperty::StaticClass()))
{
return (*(bool*)ValueAddress) ? TEXT("True") : TEXT("False");
}
else if (Property->IsA(FStrProperty::StaticClass()))
{
return *(FString*)ValueAddress;
}
// complicated type, get the property
UObject* ObjectValue = Property->ContainerPtrToValuePtr<UObject>(ValueAddress);
FString ResultString;
if (ObjectValue != nullptr)
{
UE_LOG(LogTemp, Error, TEXT("GetBasicTypePropertyValue get from the property :%s"), *Property->GetName());
for (TFieldIterator<FProperty> PropertyIt(ObjectValue->GetClass()); PropertyIt; ++PropertyIt)
{
FProperty* ChildPropertyPtr = *PropertyIt;
UE_LOG(LogTemp, Error, TEXT("GetBasicTypePropertyValue for PropertyName: %s, PropertyType: %s."), *ChildPropertyPtr->GetName(), *ChildPropertyPtr->GetCPPType());
ResultString += GetBasicTypePropertyValue(ChildPropertyPtr, ChildPropertyPtr->ContainerPtrToValuePtr<void>(ValueAddress));
return ResultString;
}
}
return FString();
}