Level unlocking and Selection screen

Hello, So I’m trying to make a level unlocking system for my level selection screen so when the player beats a level they can go on to the next level but if for some reason they can go back to that level if they want to from the level selection screen. Now I did find something that worked sort of. The issue is it will unlock the level but then once you beat that level it locks itself and then unlocks next level. How do I fix this? Here are some pictures of what I have so far. So Basically I’m using a save game that has a bool for each level in the game and then once that level is beat in the level blueprint it unlocks the level by setting the bool for that specific level to true. Then from there, the player can select an already beaten level or the level they are currently on, but the issue that I’m having is that after a level is beat and it moves on to the next it only keeps the level the player is currently on unlocked.

  1. In the final image you need to hook up your “save game object” pin to the save game object you created. Right now it is a null reference.
  2. Where do you save out your booleans? You need to save ALL booleans unlocked each time you save a game not just the one for the level the player just completed.

In your save game object “Level Select Save” you would have say 4 booleans one for each level 2-5. The first time you open the game on level 1 it would look like this.

Level 2: false

Level 3: false

Level 4: false

Level 5: false

Then you beat level 1, it unlocks level 2. You create a NEW save game object with the default values and set Level 2 to true. So now you save the game and it saves out the following:

Level 2: true

Level 3: false

Level 4: false

Level 5: false

Then you play level 2, beat it, and create a NEW save game object again with default values as follows:

Level 2: false

Level 3: false

Level 4: false

Level 5: false

You then change level 3 boolean to true and save which gives you the following:

Level 2: false

Level 3: true

Level 4: false

Level 5: false

As you can see it will only ever save the current level because you are constantly creating a new save game object. Either keep this “save” function in something like the game instance that will remember all the levels you beat and all the booleans will be properly set and ONLY save the game once when you quit. OR get a reference to the save game object initially created so that each level will work on the same “object”. This would also require you to store a reference to it in the game instance or some other global BP that is not affected by level changes.

Here is a tutorial I made on save/load game data with time stamps so you can navigate to the part you need help with.

Let me know if anything is still giving you trouble.

So I have to use the game instance?

A game instance would def make it easy, is there some particular reason you would be opposed to using it? You could do it in any actor but that actor would have to be in each level and load its data from the save game file at the start of any level that would need that information. If you do it in the game instance you only load the data in once and it persists through all levels and when you finish playing you update the save game file once with game instance data and you’re done.

Okay, So then how would I go about using the game instance for this?

You would create a boolean variable in the game instance for each level you have. Set them all to false starting with level 2. Level 1 either doesn’t need a boolean or it would default to true. When the start menu shows up have it check the game instance to see which levels should be open. Initially only level 1 would be “true” and available to play. Once you beat level one, whatever script you have that take the player back to the menu or whatever it is that lets the player know they “finished” the level, add to that a cast to game instance that will then set the bool variable of that level to true. Continue this process as many times as you need. This way the player will always have access to previously beaten levels. When they want to quit, save all those boolean values to the save game object. When you start the game again load the save game object and set the booleans in the game instance from the save game object values. The link I posted goes over how to do this if you are still confused. I forget what exactly I was saving in there, probably player score, but the method is the exact same your variables are the only difference and maybe where you call your save and load game from.

Would I be able to have this save after the player completes each level instead of when they are ready to quit? I think it would be more reliable for it to save right after they beat a level, because if for say they close the game using the close button or task manager. Then the progress that they have would be lost. And what do I hook the cast to game instance up to for the object? So here is what I have so far using the game instance, Ignore the Char Chosen that is used for my character select menu.

In image 1 you need to hook up the “save game object” return value to the save game to slot object pin. You also need to set the save game “booleans” to the same value as the game instance values. So after you set the level 2 boolean to true, drag out of the save game object and set its level 2 boolean to the output of the game instance “set” node for that boolean that way they both match and when you save the game to slot the save game object will have the same data as the game instance. As for game instance references, very easy just right click anywhere and search for “get game instance” and plug that right in. In image 2 you need to cast to your game instance and get a reference to it. Then use that reference to pull out all the boolean variables and hook them into the appropriate branch nodes for the levels. Right now each level is default true and would be unlocked. Also not sure why you need the “save game valid” check there. Seems unnecessary.