Saving/Load Boolean Array For Implementing Player Abilities (CanWalk/CanJump/Etc)

Guys, this is probably something easy, but I can’t figure it out: how to save and load the array of booleans?

I’m building the first quest and the part of this quest is step by step enabling new abilities for the player, i.e. booleans “Is Walking Enable?” and “Is Jumping Enable?” etc. I’m setting it this way during quest:

And this is the initial set up inside the quest before running it (everything is disabled):

This is the loading part inside SaveGameActor component…

…connected to this part of Break Strut Save:

Снимок экрана 2021-12-23 224401

While saving part looks like this inside SaveGameActor component:

It seems to load these booleans out of array…

But I can’t move/jump/etc. after loading the save game. These booleans are setting correctly during gameplay:

What could I do wrong here? What’s the proper way to save & load booleans to implement player abilities like these ones?

I’ll be very grateful if someone will take their time to reply & help me solve this issue. (I can upload a project archive in a cloud storage if you’ll want to look at it by yourself)

I see you have all those bools + the array. You are populating the bool array and saving / loading it. But how are you connecting the array to those bool variables after loading? Assuming that the individual vars are the ones controlling the branches in the controller, not the array.

1 Like

After loading… I call the custom event from SaveGame component which is located in player controller:

Снимок экрана 2021-12-24 080912

And it supposed to set it one by one, manually:

Something to note: I’m setting player state changes in quest BP, loading/saving it in boolean array in savegame component and having the second boolean array in player controller as a main one. (Haven’t found any tutorials about it, so not sure if I’m doing it right).

Try printing the length of the array after loading, also compare it to the values of each variables.

IMO a Map container will really help you organize all those bool. It’s something I recommend you explore after you’ve fixed your issue. Something like:

Did a quick test tryng to understand better your issue: Save, Load and Delete Map - YouTube IMO your problem could be a broken reference or the order of save / load / set the variables.

Hope this helps.

1 Like

Thank you very much!

I’ve tried to compare array length and it seems like it’s 10 when it saves and 0 when I load it.

Check your log when saving or loading for “Access none…”.

1 Like

Nope, the only errors I get are according to the saveslots I haven’t used yet (I’ve used saveslot 1 for tess). Everything else looks fine to me…

Here’s what my load game BP looks like:

Here’s what save game BP looks like (open in new tab to zoom in):

PrintString of the boolean arrays during save, load and the way it should actually work. (First part of the image is a start condition (player can’t move/jump/etc), second is what it looks like when I load it after saving and the final part is what it should have looked like if it would save/load correctly)

Снимок экрана 2021-12-25 220605

Still can’t get it…

Can you share this through here? You just have to copy / paste and its free :upside_down_face::

If the loaded array != saved array, then you could be saving and loading both on a different slot. The engine doesnt create arrays on its own, its pulling it from somewhere.

Can you share this through here? You just have to copy / paste and its free :upside_down_face::

Yeah, sure. Here is it, if I did it right: BP Save/Load posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

If the loaded array != saved array, then you could be saving and loading both on a different slot. The engine doesnt create arrays on its own, its pulling it from somewhere.

I thought the same, it loads as it was empty… when I was adapting it to my needs (quests & save/load are extensions, first person controller is made by following YouTube tutorials), I wasn’t sure if I did this part right:

Maybe that might be the key…

Did you check the length of this? The PlayerStates bool array in save game after loading, not the copy.

If this is an option I could try and test it out myself. Feel like it could be a lot of back and forth not having the complete picture.

Yes, I’m afraid I won’t find the solution alone. I’d be very grateful if you could look and tell me how could I change my additions to this code to make it finally work. Sending you the link to the project archive in PM.

1 Like

It now saves, loads and applies the saved values to the bools: ScienceQuestGame - Save / Load Working - YouTube

Sent the 2 BP I modivied through PM.

Fixes are commented in red. For example:

NOTE: Having so many bool variable having to populate an array will be a problem later on because when the variables change during gameplay, the array will not update. Right now the array is populated by QuestTutorial actor at Begin Play. After that I did not see anything that updated the array in the MainHeroController. This means that when you progress through the game and the variables change, save game will have no way to know.

This is why I suggested you use a Map container.

1 Like