TArray and FScriptArray are layout compatible, and are required as a basis for the property system. There is also FScriptMap, FScriptSet and FScriptSparseArray which are layout compatible with TMap, TSet and TSparseArray respectively.
However, while it’s always going to be the case that these FScript* classes have this compatibility, it’s generally not recommended to use them, as they are more an implementation detail of the UE4 reflection system. Correctly reading and manipulating elements within containers and honouring object lifetimes is considerably more involved than just casting to those classes and using them. What is your use case?
I can’t comment answers on my question, so I post comment as answer for you, Steve Robb.
My case is serialization exception where I serializing specific struct with TArray field.
I need to get this field as TArray:
// This struct is FMyStruct?
if (StructStructure->GetName() == GetNameSafe(FMyStruct::StaticStruct())
{
// And then find field "Data" in this struct
if ( UProperty* field = FindField<UProperty>(StructStructure, "Data") )
{
// This is TArray<uint8>, I need to cast to property value to TArray:
const FScriptArray& script_value = field->GetPropertyValue_InContainer(StructData);
...
}
}