Getting properties of a struct using FProperty

Check out ‘Engine\Plugins\VirtualProduction\LevelSnapshots\Source\LevelSnapshots\Private\Selection\PropertySelection.cpp’ at ‘FLevelSnapshotPropertyChain::FindPathToProperty’.

You’ll want to do something like:

FProperty* Struct = Target->GetClass()->FindPropertyByName(FName("MyStruct"));
	
if (const FStructProperty* StructProperty = CastField<FStructProperty>(Struct))
{	
    for (TFieldIterator<FProperty> It(StructProperty->Struct); It; ++It)
    {
         const FProperty* Property = *It;

        if (Property.GetFName() == MyPropName)
        {
	        // Here we have the property inside the struct
        }
    }
}

Then you can do what you were doing before where I assume you were casting single FProperty members to FFloatProperty or something then calling SetPropertyValue. The only difference is that you can’t use UObject as your container void*, you’ll have to use the actual struct void*.

void* StructPtr = StructProperty->ContainerPtrToValuePtr<void>(MyObject);

MyFloatProperty->SetPropertyValue(StructPtr, 1.0f);
2 Likes