Saving a game with multiple levels

For something like this, you would want the save game functionality be accessible by any map, so the GameInstance would be the best place to Save / Load since it remains persistent throughout your game.
I would recommend you storing your level specific information in a struct and store it as a map in your save game object.

  1. Create a level information structure and add the desired properties. You can do this by right-clicking in your content directory → Blueprint ->Structs

  1. Create a custom Game Instance class or open your game instance if you have one already. Be sure when you create your custom Game Instance you update your project settings to use this custom Game Instance class.

  2. Create a custom Save Object class and all your struct as a map with a string key.

  1. In the custom, GameInstance class create an event you can call to save your game for the current level.

  1. Create an event you can call to load your save information. This will check to see if we have any information saved about the current map.

  1. Amend your current logic in your game to use these two functions created, by using GetGameInstance → CastToMyCustomGameState → (Get the name of the function).

You will obviously modify the structs so it contains whichever data you would like. Note, because I used a map, this means you will only be able to save one set of data per level. If you want to have multiple saves per level you will have to modify the way the data is saved and how it is accessed.

I hope this helps. I quickly rushed this on my lunch break without testing, so if this code doesn’t work directly, it will at least give you an idea of what we are trying to achieve.

Good luck :).

3 Likes