Need Help Saving And Loading.

I have a Save/Load System setup. Most of it works, but i cannot get it to save/load over different levels. I have it save on end play and load on begin play what am i doing wrong?.

Save Function

Load Function

If you are transitioning from Level 1 to Level 2, you are saving when you finish, loading that save and then immediately saving over it. No data would be different. If you want to save/load for separate levels, you need to set up an array to save each level’s score and load from that.

's a thread on I posted on a while back. Should still be relevant I think.

Assuming you want to save/load a single value persistently across all levels-

There is no reason to save the game to the slot if it already exists in your load function.
Matter of fact you have no reason to create a save in your load function.
Your load function has no reason to save the game at all.

I can’t actually see a fault in your logic however. About the only thing I can think of is that the cast somehow fails.

If you want a save for each level- you can ignore what I said about loading; you need to change the slot name.

So level 1 would handle “L1” slot save, level 2 would handle “L2” slot saves. If this is a BP library, change this over to use a parameter for the slot name. (drag the slot name pin to the function node)

I have serveral different variables i need to save. The main being i have a shop where you can spend ingame currency that you gain from the score. When you buy a upgrade or something in the shop there is a boolean that activates it. And you currency goes down. I have those setup the same as the score functions. Will this be able to be applied to those also?

Edit: This shop is part of the main menu which is on a different level.

I’d have a save for any data that you need to be persistent across all levels, then have a save for each independent level if you need it.

Say each level needs a leaderboard/high score- you can have each level have a save, and if they’re independent of a player you don’t need to worry about anything else. ‘Level1’ is a good slot name. You’d use this in a similar way to arcade machines.

Say you need to save each player’s state for any particular level (personal bests/ghosts/etc), you could have ‘<PlayerSlotName>_<LevelName>’ as the slot name. Alternatively, this could just be stored in the player’s save slot, in a similar way to Gooner’s suggestion.

Then, for anything like currency that needs to apply globally, you have the player’s slot, which could be entered by the player when creating their profile, or just ‘Player<Number>’.

How would you suggest to activate the boolean from the shop in Main_Menu to Level1?

Also should everything i need to save and load be in the same slot?

No, you can have as many slots as you want, but each slot must have a unique name. That’s the ‘slotname’- it’s really just a file name. You could have everything in one save unless you need each level to save state for some reason (again, arcade high score lists come to mind) or have multiple player save slots.

You can also have as many of the same save game type (So that means you could have 30 ‘Shooter Save’ SaveGames) as you need.

As for how to save a boolean? Make a save slot for the player, or use the one you have. Save the boolean in that. Load it into the level, and then store it in a variable.

Is there any reason you’re using saves instead of simply putting your persistent variables into a Game Instance class? I have only been using saves in the traditional sense of using save games (at begin play, and when quitting). All other persistent information I always keep in my Game Instance. This isn’t so much of a big deal in the game I’m working on right now, but my Labyrinth Larry game was just a single level that was always reloaded and regenerated upon success or failure and this method worked flawlessly.

gameinstance.png
as
For the game I’m working on right now, I keep my number of lives as a variable in my Game Instance class. It’s always just a quick (pure) cast away when I need it.

I got it to work by doing what you said . I changed the slots i needed for for each level to a different slot and called the ones for that level in the level blueprint. Im still having trouble with the boolean working now. When i purchase the upgrade the currency saves and loads and after purchase it should save the boolean to be loaded when you’re back ingame you can use the thing you purchased. But it still thinks its not active. Anyone know why?

Ive tried everything i can think of and cannot get this one boolean to save/load i have it setup the same as the ones that are working just fine. I don’t know whats going on.

Find everywhere that this bool is being used. Maybe it’s being overwritten somewhere? I’ve run into that a ton of times. You load it from the save and it’s fine, but you forgot you had a BP that runs a BeginPlay event right after that sets it to the default or something like that.

If it’s set up like the others and they all work, that’s a likely place to start looking.

Firezown: If you have per-level state, AND per-game state, then you need two save game objects.
Whenever you shop in the show, save the boolean and credits amount into a savegame called “GlobalState”
Whenever you load a savegame, also load the GlobalState savegame. You don’t need to create that one in the load functions – if it doesn’t exist, assume defaults.

You mean have two different savegame blueprints? Wont that just do the same thing with more nodes?

No, I mean multiple savegame slots.

If you try to write “high score for level 3” to the same file as “unlocked features for player A” then when the player A goes back and loads level 2, those unlocked features will be locked again, because you will load the unlocked player feature data from that savefile.

So, create one object that stores all the player unlock data (perhaps a PlayerInstance blueprint?) and another object that stores all the current-level data (like an actor in the level, with some well-known name or interface.)

When time comes to “save,” you save the player instance data to a savegame slot named “global player” and you save the level-specific instance data in a slot named “level 3 state.”

I already have 2 different slots. One Is Main thats for stuff in the main menu level. The other is Level1 and that controls all of the stuff in level one.