I have a path of an actor or component’s property, it is something like this:
/Game/Map/fakeWorld.fakeWorld:PersistentLevel.BP_fake_C_9.StaticMesh.bHiddenInGame
or in PIE mode:
/Game/Map/UEDPIE_0_fakeWorld.fakeWorld:PersistentLevel.BP_fake_C_9.StaticMesh.bHiddenInGame
I am pretty sure that the path is correct. And I try to use reflection to reach the property and set value to it. It turns out that the property value has been changed in the details table every time, but the viewport did not change at all. To explain further, I run the valueChange funciton in editor mode, the property value in the details table will be changed. And I click play, the change will be applied. I click end-play, the change in viewport disappears and the details table remains the change. Weird.
Here are the steps currently:
what i know:
ObjectPath
PropertyName(which for now I ensure this is a type float property, I use float to test. In the future all the types will be covered)
Several methods I tried, they failed in the same way
UObject* FoundObject = StaticFindObject(UObject::StaticClass(), nullptr, *ObjectPath);
FProperty* FoundProperty = FindFProperty<FProperty>(FoundObject->GetClass(), *PropertyName);
FoundProperty->SetPropertyValue_InContainer(FoundObject, FCString::Atof(*PropertyValue));
if (const FFloatProperty* FloatProperty = CastField<const FFloatProperty>(FoundProperty))
{
if (float* ValuePtr = FloatProperty->ContainerPtrToValuePtr<float>(FoundObject))
{
*ValuePtr = UKismetStringLibrary::Conv_StringToFloat(*PropertyValue);
UE_LOG(LogTemp, Log, TEXT("Set property %s to %s"), *PropertyName, *PropertyValue);
}
}
if (auto* FloatProp = FoundObject->GetClass()->FindPropertyByName(*PropertyName))
{
FFloatProperty* PropField = CastField<FFloatProperty>(FloatProp);
PropField->SetValue_InContainer(FoundObject, FCString::Atof(*PropertyValue));
//FloatProp->SetPropertyValue_InContainer(FoundObject, FCString::Atof(*PropertyValue));
//float* ValuePtr = FloatProp->ContainerPtrToValuePtr<float>(FoundObject);
//*ValuePtr = FCString::Atof(*PropertyValue);
//FloatProp->SetPropertyValue(ValuePtr, FCString::Atof(*PropertyValue));
UE_LOG(LogTemp, Log, TEXT("Set property %s to %s"), *PropertyName, *PropertyValue);
}
I even try something like importText_direct, not work as well.
Thanks for your answer. Much appreciated.