TArray of UObjects getting garbage collected

We have an inventory system in our game that uses a TArray of UObjects to represent slots in a container.
The declaration for the TArray uses the UPROPERTY specifier to prevent the objects from being GC’d.

The inventory container is created within our derived UGameInstance object at startup in the function UGameInstance::StartGameInstance().

When changing maps, the container persists, but all of its slots get garbage collected from its TArray, causing the game to crash.

We assume that having a TArray of UObjects is compliant with the documentation on Garbage Collection:
“The only container that is safe to have UObject or UObject-derived pointers in is a TArray”

1 Like

The problem seems to have been solved by manually assigning names to the UObjects.

1 Like