Download

How to use UArrayProperty and/or FScriptArrayHelper to get the values of an array through reflection

Hello,

I was wandering if anybody knew how you can retrieve all the values of an array of FStrings using Unreal’s property system (reflection)?

I currently have this?


else if (objProperty->IsA(UArrayProperty::StaticClass()))
{
	UArrayProperty* arrProp = Cast<UArrayProperty>(objProperty);
	UProperty* innerProp = arrProp->Inner;
					
	if (innerProp->IsA(UStrProperty::StaticClass()))
	{
		const uint8* PropertyValue = arrProp->ContainerPtrToValuePtr<uint8>(obj, 0);
		FScriptArrayHelper ArrayValueHelper(arrProp, PropertyValue);
		for (int32 Idx = 0; Idx < ArrayValueHelper.Num(); Idx++)
		{
			const uint8* elementRawData = ArrayValueHelper.GetRawPtr(Idx);
			//how do I get string from raw ptr?
		}
	}
}

Any help would be appreciated,

Thanks

So I figured it out.
For anyone interested:
You can retrieve all the values of an array of FStrings the same way you can retrieve a struct’s value:


TArray<FString>  ArrayOfStrings = *arrProp->ContainerPtrToValuePtr<TArray<FString>>(obj);