Saving & Loading Interactive Light On/Off States?

Another stupid question: what’s the proper way to get all instances of the blueprint in level, save only ones with boolean on and then load its state based on this boolean after loading game save?

I have a light switches and would like it to be saved. Can’t get a proper way to do it using array and loop…

BP of the light switch:

Part of loading BP in save game component:

Part of saving BP in save game component:

It must be something dead simple… where am I wrong in this part?

It’s just a bool array. Each light switch has an integer ID, which is it’s index in the array.
Whenever they’re used, they save their status in the save game, you don’t need to do it all in one go. You only need to code it in the light switch blueprint once, the rest happens automatically.

When the game starts again, each light switch knows to read it’s own status from the save game and set itself accordingly.

Trying to do it all at once is a bit of a mare, and combine that with structures, it’s no wonder you have a problem… ( they’re not easy to work with ).

1 Like

Thank you for your answer! I’ve tried to implement it in light switch BP, but it’s not working. What am I missing here?

Here’s blueprint: Lightswitch BP posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

I don’t see anything about the save game in that code. I’ll give you an example in a while…

Thank you very much, I really appreciate your help.

Alright, this is it.

In your level BP, do this:

In the save game you need an array for the lights:

image

Everything from here onwards is the light BP ( it’s the saving and loading that matter of course, not how I make the bulb ):

Switch on and off ( read a bit further, and do the UpdateSavegame event first )

This is the update savegame custom event

and probably the most crucial part. You need to load when we start playing:

The lightswitch BP has an integer ID:

image

When I put them in the level, each switch needs a different ID

I numbered them 0, 1, 2

lights

Notice I can stop playing and when I start again, the lights can remember their state. Because I put it in the save game.

1 Like

Thank you very much!

This solution is great, but I can’t find a way to adapt it to the save/load system I already have. Could you give me a hint how could I fix it to properly save/load from slot to save lights on and off?

Updated light blueprint: Lightswitch BP (Updated) posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

Save/Load blueprint: Save/Load BP posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

What’s the right way to use LightID integer from light BP in Save/Load BP? I think that’s the only thing that stops it from working in my case…

Your light BP seems good. Sorry, can’t debug your save/load BP, it’s a total nightmare :wink:

You don’t need anything to do with the lights in the save load BP, because the lights are already managing themselves. It’s a much easier way to do it.

Basically all of that stuff in the save/load BP needs to go in the individual BPs, then you might be able to see what’s going on.

Hey, I’ve finally managed it to work - at least, partly.
Thank you! :smile:

Something weird is going on, though: it works perfectly when I enable/disable lights and then load the game. When I enable/disable lights, click “Save game” and then “Load game” - light status won’t load. That’s strange…

Here’s video play through replicated these issue: TheStringTheory Preview [NetMode_ Standalone] (64-bit_Windows) 2022-03-31 20-41-12.mp4 - Google Drive

Light BP in configuration that worked for me: Lightswitch BP (Updated 3) posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

Right. Do you get it that you don’t need to save.

When the lights change status, it IS already saved. Try changing a few and then restarting.

So I’m deducing, there’s something shifty going on behind that save button, which no doubt involves saving an out of date version of the save game ( on top of the good one ), which is why it’s not working :wink:

If you want the game to only save when you say so, the whole structure is somewhat different.

I you want to have control over when it saves, come back to me and I’ll show you how… :v:

Hm… yeah, the whole point of a question was to save states of some objects (I wanted to learn it with toggle-able lights) via manual saving/loading (old school thing). How could I adapt this blueprint?

Now we need to code something in save game actor, right?

Remove all calls to ‘update save game’ from the light.

Make the on/off change a bool

Now the ‘update save game’ code, uses that bool

When you press the save button, then do a foreach on all the bulbs, and call the ‘update save game’

Should we change something in Event Begin Play in light BP too? It still uses branch with ID condition.

Absolutely right.

Change that begin player to a custom event ‘load status’ ( or something ) and do the same thing with a foreach loop from your widget to load the lights.

This way?
Should we use the ID of light or something else?

(This part is loading in a sequence when the button ‘Load’ is pressed. What am I missing here?)

This

take the begin play off, and make it a custom event. Call that event for each light.

Are you sure we shouldn’t change anything here, in this custom event?

The light still needs to do exactly what it did before, but only when you tell it. So it stays the same, but does it when you say, not on begin play.

I wish it would work, but it’s not.

Loading part in SaveGameActorComponent:

Load Status custom event in light BP:

When I click ‘Save’ menu button, it saves perfectly.

When I’m loading it, it goes all blank. Like if branch was set to false.

This one. Something is not right… :neutral_face: