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.
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.
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.
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?
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!
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.