Serializing TArray in SaveGame

If you are using the engine’s vanilla save game structure, you won’t be able to save object instances.

The save game will automatically pick up properties of type “Plain Old Data”: strings, numbers, and structs of Plain Old Data properties such as TArray’s. (I’ve also been able to save Meta Class objects, but I think this undefined behaviour and likely to break some point in the future, see note below).

What you can do is serialize your object instance to some struct representation and save that in your save game; and then build object instances from the saved structs when loading.

If you want to serialize object instances themselves, you’ll have to build your own infrastructure, using something similar to Rama’s:

Background:

if you create a property that is an actual pointer to an UObject pinstance, the save game won’t save the actual object, but the “reference”. When your game starts up again, that reference will point to an instance that isn’t there anymore; at the moment of this writing, it works for metaclass objects because of how they are built and the way the reference is saved.