We ran into this build error today. While we were able to work around it easily by creating a wrapper struct for the TArray, we were curious why this is disallowed, and wondering what would break if we modified UhtArrayProperty to leave UhtPropertyCaps.CanBeContainerValue as part of the PropertyCaps value.
Steps to Reproduce
- Attempt to add a TMap property to a UObject-derived class using the UPROPERTY macro, with any valid type as the key, and TArray<any valid type> as the value.
Hi there,
Unreal Engine doesn’t allow TArray (or other containers like TSet or TMap) to be used directly as values in a TMap for a number of different reasons. This is a restriction built into the Unreal Header Tool (UHT) to avoid issues with:
- Serialisation (There are potentially edge cases where data might not serialise correctly, or cause runtime crashes during save/load operations)
- Reading the value in blueprints (bps don’t support nested containers like TMap<FString, TArray<int32>> well. There’s no UI in the Blueprint editor to display or modify maps with array values, which would be a limitation even if you made your engine modification.)
- To avoid additional garbage collection complexity (nested containers complicate memory layout and object reference tracking, which adds gc complexity).
In general, these systems expect property types to be straightforward and predictable, which nested containers aren’t. If you try to remove the restriction in UHT to allow this, your code might compile, but it could break in subtle ways across the engine, especially in the editor or with Blueprints. The recommended approach is to wrap the TArray in a simple USTRUCT as you have done already, which keeps everything compatible with Unreal’s reflection and tooling systems.
Kind regards,
Thomas