I’m trying to save a polymorphic array of UObjects into my savegame. The binary appears to contain some information about the array, including the types of the entries in it, but no entry data. I put the SaveGame attribute on a few UProperties, doesn’t seem to do anything.
It seems like this should work, polymorphic serialization works all over the engine?
Also shouldn’t Ar.ArIsSaveGame = true in UGameplayStatics::SaveGameToSlot() ?
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.