Storing Objects / Arrays of Objects in SaveGames

Hi y’all :slight_smile:

I’m trying to save my game state in a savegame. The simple tutorials work fine, of course. Now I’m stuck at the point where I need to store an arbitrary number of states.

My Savegame contains three arrays for that purpose:

image

Each of the array elements has it’s own structure. For CharacterState, this includes inventory content, Transform etc.

I hand a filled object to the save method, which my debug method shows me:

image

When loading, the array elements exist, but they contain no data / default values:

image

Basically this wraps up what I’m doing:

Setting a break point, my Savegame object arrays seem to contain gibberish:

I’m stuck and would really appreciate If someone could point me in the right direction… Thanks in advance!

for debug purposes, let’s consider only the first array. can you after saving, put a small delay and try to retrieve it back, add print string to see if it getting retrieved?

you cant save objects, you have to save the Data in the objects, usually in a struct or some container.

Objects are a reference to something that exists in the world and since the world gets destroyed that object no longer exists.

with a typically load system you recreate those objects, ie you can save the Class and its variables then on load spawn a new object and then copy any variables

3 Likes

Thank you so much for this. If I wasn’t nearly bald anyway, I would have torn my hair out about this…So, now I created structs for all the stuff I want to persist and it works just fine.

Solution in Developer lingo: Savegame only works with value types, not reference types. References are NOT serialized.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.