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:
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:
When loading, the array elements exist, but they contain no data / default values:
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
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.