Saved Game only storing last value of Map

I have a checkpoint system in my game that logs each checkpoint reached into a map that can be written to a Save Game object if the player chooses.

I am trying to create a screen in the main menu that will list each checkpoint as a button using a for each loop. However, after the game retrieves the map from the Save Game object and converts it to an array, only the most recent value in the map is displayed.

It seems as though when the game saves the data to the Save Game object, it only stores the final value in the map. Why would it be doing this?

You should do some debugging there. The map, you are passing, does it contain all the keys? Try to print them out. When game loads, does the map contain all the keys? It should really work out of the box. I have maps in my savegame, and they work fine. Probably you are passing a map that has only last key. Or you are reading it wrong. Try to debug these two.

Every map has keys node. Iterate through it to make sure you have them all when passing it to the save game, and when you are reading the savegame information.

1 Like

I’ve debugged them on the save game function, and it seems to write everything to the save game object. When I tried the same thing on the load game function, only the last one was returned. I’m using the Values node instead of the Keys, but had the same issue either way.

To be honest, I am not sure then. Either something else is changing it, or something else. I would have to debug myself to know why it’s like that.

I think there may be one of two things going on here

  1. When you add a key to a map, if there is a key with the same value, it gets overwritten. You can only have one value per key, in a map.

  2. You have a problem with the way you’re addressing the save game. Here’s my save game 101, just in case

Ah yes, now that you mentioned it @ClockworkOcean, it could be that SaveGame is created multiple times - on every execution of the for loop. And therefore only last entry is saved.
@sweeetjd make sure you only create one instance of the savegame. Do it when game initializes, not in some actor that is on the level.

1 Like

I don’t believe that it is saving multiple times. The For loop is only used to populate a widget with buttons. The game does create the save on Init, so as far as I can tell that isn’t it either, but I’ll keep looking just in case.

I tried adding a bit of code to the end of the Save Game function to make sure it was saving and loading correctly. In this code, the game loads the slot it just wrote to, then displays the map. When I do this, the map loads all values correctly. However, using the exact same code in the actual Load Game function results in only the final value, along with a blank return line for some reason.

I did notice that the issue occurs after the game switches to the main menu level, which has none of the objects referenced in the map. Could this be a problem?

Ah. Are you saving object references? That won’t carry across between levels, I don’t think.

No, I’m not. I’ll try that.

Or wait… do you mean save game object references, or references to objects/actors in the level?

Objects in the level. What I mean is, references to objects in your level don’t mean anything when you change levels.

I see. Yes, that’s what I’m doing. What’s odd is that it still registers that something was there in the map when I switch levels. It’s just not the entire map.

Sounds like I’ll have to find an alternate solution. Thanks for your help!

No worries.

Thing is, why are you saving them?

If you want to make them reappear, you can save the class and location/rotation.

And so on…

This game is similar to crash bandicoot, except that instead of a warp room, the game is presented as one giant level with periodic breaks that signal the end of the level. At those locations the player can choose to save a game. In the main menu, the player can then choose one of those levels when they continue a game. I was hoping to just have the game load in all of the reached levels in the main menu.

I think I can just store the names of each level break in an array, and send that to the main menu.

Hmm, if it’s one big level, then those references should be ok.