Saving/Loading question

So, I’ve got a saving/loading system set up. and it all works correctly. however, I recently starting toying around with saving/loading level states. and I seem to have run into an issue.

This is my level blueprint:
At the start of my level, I grab my save file
loadgame

I then check to see if the cutscene has been played with a branch.
boolcheck

If the cutscene has not been played yet, I play the cutscene and then set that its been played to true. so it won’t repeat upon restarting the level.

This works as I intend it to work, until I start trying to save the level states for my levers and doors.

This is my Door BP: at begin play I check if the doors are open/levers pulled and if so, I apply the open/pulled states.

After the door opens I save the game.
Untitled

Again, this works as intended. If I pull a lever to open a door, and I reload the game. the doors will be opened, and the levers will be pulled like they are supposed to be. However, the cutscene variable inside my level blueprint don’t seem to save/load if I open a door. Meaning the cutscene will always be played when I restart the level/load the game… If I disconnect the begin play on the Door BP, the cutscene variable will save.

Also, if I load the game twice, (The cutscene plays both times after opening a door) and then I load the game. the cutscene variable finally saves? and it won’t play upon loading a third time.

You probably want to set up centralized loading and saving of your savegame.

It looks like you are loading your savegame multiple times at BeginPlay, and storing copies in variables in various objects. These copies are not synchronized.

When you set SaveGame->MTEntranceCS=true in LevelBP and write the savegame, it effectively rewrites the entire savegame with whatever data you have in the savegame variable in the level BP (including MTEntranceCS).

The DoorBP also has a copy of a savegame object, loaded at BeginPlay, in which MTEntranceCS has not been modified. When you open door and set OpenState=true and write the savegame, you are rewriting the file with MTEntranceCS=false and OpenState=true.

One possible solution, would be to reload the savegame before modifying & saving it each time, ie. instead of storing it in a variable, do Load → Modify → Save. This way each object retrieves the changes made by other objects before rewriting the file. However I wouldn’t recommend this approach as it adds significant overhead that could smash performance later on.

A better solution would be to set up a centralized place to hold your savegame object variable, and then all blueprints would retrieve it from that place, such that there is only one variable containing one copy of the savegame object in memory. You would load it only once, and access/modify/save it whenever you want. It could work in a subsystem or any easily accessible singleton class such as GameMode, GameState, or GameInstance depending on your needs.

1 Like

I really appreciate you taking the time to type that all out for me! I’ll give this a shot! I’m a little confused on the last part though, I’m sorry :slight_smile:

I would create the save game object variable inside the game mode for example, and then I just cast to my game mode, and grab the save game variable that way?

That’s exactly it.

1 Like

Thank you I appreciate the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.