How do I serialize properties in child objects?

I’ve got a list of dynamic actors in my game which need to be saved and restored. Most of my base classes are written in C++, and my child objects inherit from these base classes and are usually blueprints.

My game state contains a list of all of my active base class objects. For example, I’d have an array of pickups. What properties those pickups have is up to the blueprint to decide. Let’s say I create two types of pickup in blueprint. One is a SpellOrb, and I give it two additional properties (an enum and an int32). The other object is a health potion, with two completely different properties (in32 and FColor). I might have 20 more pickup objects, who knows, who cares – we just track and care about the base class.

Now, I need to save the state of the game and then restore it. I loop through all of my pickups in Game State and I create a “PickupRecord” struct which will contain all the data I need. The child objects will need to save their object specific properties so that they can be properly stored (imagine its instance specific data). I found a way within the APickup object to loop through every single UProperty object in child actors which are marked with the CPF_SaveGame flag. Any child object which wants a particular variable to be saved to disk just has to mark the variable as “SaveGame”. However, I don’t know how to get the data value stored in the UProperty variable. This is where I’m stuck.

Should I create a BlueprintImplementableEvent which receives an array of bytes, and let each blueprint handle the implementation for it? Or is there a way to do this on the C++ side with the base object so that blueprints don’t have to worry about this? How do I save a child object and all of its properties from the parent class, without knowing anything about the child object?

I figured it out.

See this forum post I wrote up for the answer