I am writing a RPG system in which you attach components to the player (Composition based design).
I have created a few components including, level, skills and quest components.
The way I have it at the moment, the component contains a TArray of structs to hold data about each quest etc…
However the objects held in the TArray are being destroyed, which is not what I want. Normally I would use a pointer to manage the lifetime of my object however I cannot have a TArray with pointers to my structs.
As far as I know, structs are not garbage collected - that’s why you generally require an implementation for “Destroy()” on them. In UE4 they are intended to mostly be used as value types (e.g. FVector).
I do recall that for some reason it’s not safe to point to a struct belonging to another object - not sure if this helps.
Do you have some more information on exactly what is going wrong?
If the structure in the array is a plain C++ structure (not inheriting from UObject), they will be destroyed when the owning class is destroyed.
If they inherit from UObject (which I guess is the case, otherwise I don’t see how it is possible they are destroyed just like that), they will be garbage collected automatically, provided you put the UPROPERTY() macro on top of the array.
It would help to see some code to better understand your problem, and try to answer it the better way.