How should I make a saveable variable that can have inheritence?

I’m wondering how I could save a variable that has inheritance. All my buildings have to save to a single type of struct: SaveStruct_Structure, so adding unique fields for each structure is pretty annoying. Having a variable that can have inheritance and save would be really helpful.

Up till now I’ve been using a string to string map and parsing the data, but it’s really ugly.
I would’ve preferred something like:

Parent class: SaveObj_BuildingData
Child of said parent: SaveObj_ABuildingsCustomData
Another child of said parent: SaveObj_AnotherBuildingsCustomData

Where in the struct I save I request a SaveObj_BuildingData, and the individual classes can cast it to what they know it is.
But, to my knowledge, you can’t save an object.

I’m not sure how to go about this.

Any UObject can be marshaled to and from storage, but some additional logic may be needed to make that work well. For example, when loading an AActor, you have to figure out whether to make a new object, or apply the state of that object to an existing actor.

Thus, you have to use a C++ subclass of SaveGame to add UObject or AActor subclasses. The Blueprint SaveGame class is intended for simpler games that have simpler state. As your game grows in complexity, some C++ will usually be needed.

Here’s a Wiki walkthrough of one way to do it:

1 Like