Your (FProperty* Struct) does not contain MyStruct values, it only contains information about the “MyStruct” property within Target class.
To get a pointer to your struct instance in memory you need to use ContainerPtrToValuePtr.
Then to get information about the properties within MyStruct, you need to access MyStruct reflection data. This is generally done via FMyStruct::StaticStruct or StaticStruct<FMyStruct>, however if you don’t know the type at compile-time you cannot use that here. Also as far as I know there is no GetClass() equivalent for structs.
Fortunately, that information is held in the struct property information, you can access it by casting to FStructProperty.
Here is a working example :
template<typename T>
T* GetPropertyValueWithinStruct(UObject* Target, const FName& StructPropertyName, const FName& PropertyNameWithinStruct)
{
// Get the reflected struct property
FStructProperty* StructProp = (FStructProperty*)Target->GetClass()->FindPropertyByName(StructPropertyName);
// Get a pointer to the struct instance
void* StructPtr = StructProp->ContainerPtrToValuePtr<void>(Target);
// Get the struct reflection data
UScriptStruct* StructReflectionData = StructProp->Struct;
// Get the reflected property within struct
FProperty* PropertyWithinStruct = StructReflectionData->FindPropertyByName(PropertyNameWithinStruct);
// Get value of property within struct
return PropertyWithinStruct->ContainerPtrToValuePtr<T>(StructPtr);
}
Usage (assume MyField is an int32 property in MyStruct) :
if (int32* ValuePtr = GetPropertyValueWithinStruct<int32>(this, "MyStruct", "MyField"))
{
UE_LOG(LogTemp, Log, TEXT("Result: %i"), *ValuePtr);
}