Hi,
I understood a few things about Unreal garbage collector but here I’m stuck.
I have a UObject derived class holding a TMap to UStruct by value:
USTRUCT()
struct FSomeStruct
{
GENERATED_USTRUCT_BODY()
float value1;
float value2;
}
UCLASS()
class USomeCollectionManager : public UObject
{
GENERATED_UCLASS_BODY()
private:
TMap<SomeKey, FSomeStruct> Collection;
}
The “Collection” member is regularly wiped out by the GC (which I can verify by explicitly calling it using “obj gc”).
The issue is that:
- I cannot make the map a UPROPERTY since they do not handle maps
- I cannot use AddReferencedObjects since neither the map nor the FSomeStruct is a UObject
What would be the best thing to do here, in order to force the map to be referenced by its owning class and prevent it to be wiped out?