I really need some help on my save system, I’m having some trouble figuring out how I can save and load the states of my doors. They all have a similar Boolean variable called IsDoorClosed? I have a BP_SaveGame which has all my save game variables and my BP_gameinstance I just don’t know where to start with setting it up through all the doors any help would be greatly appreciated
The simplest way (not necessarily the best if you have a huge amount of states to save, but for arguments sake we’ll assume it’s a simple setup with only a few doors) is to simply assign an integer variable to your door to give it an index, and a boolean variable for whether the door is closed or open.
In your save game if you have an array of door open bools then when the door is spawned you can load your array from the save and get the value from the array by the doors index.
You just have to make sure that every time the doors is opened or closed and the state of the IsDoorClosed? bool is changed you save the updated value to the array on that index.
Sorry if that’s not exactly what you were after but feel free to clarify if you need more specifics.
If we imagine that not all doors have the same state when you start up the game for the first time, you can go through all doors with the “Get All Actors from Class” node, then use a Map (Array that stores Keys with Values, in your case a unique Door with a boolean value) to store the state of each doors.
You can go through that easily with a “For Each” node.
Then on loading you do the reverse process, get your saved Map and use “For Each” to retrieve each door status.
Here are the screenshots for the solutio:
save game with a map linking Door BP instance to Boolean state
when called, that bit of logic will grab all the exisiting door BPs in the level and save their reference together with their open/close state in the save file map above
on loading, this code will collect all the exisiting door BPs in the level and try to match them with the instances in your save file, recalling their saved open/close state