There is a light source that turns on when a player overlaps a trigger box, this only affects that light, no other copies of it in the level turn on unless they are also overlapped by the player.
The light source has logic to save its ‘light on’ status to a variable and write it to the save game.
When the game is loaded from the save game, all lights are on, even the ones the player never overlapped with or hasn’t yet.
How do I make it so that lights the player hasn’t overlapped with yet remain off? Like it does when playing the game, it seems to change its logic when resuming the game.
Hopefully that makes sense
To help illustrate…
The Blue star represents the player
The Pink circle represents the activation trigger
The Green circle represents an Active light source
The Red circle represents an Inactive light source
Player starts the game, enters the light trigger radius, light turns on, status is stored in save game
Player stops and exits game, noting the second light source (duplicated from the same light source that is now activated) was never activated
Player starts the game by clicking Continue Game, but BOTH light sources are active even though the player didn’t overlap the second one in the previous session
The problem is that when you turn on that light, it’s turning the “LightActivated” Bool ON. That’s great, that’s what you want it to do… BUT EVERY light is using that bool! So when you go to load the game all of the lights ask if that bool is true, and then they turn themselves on based on that.
You will probably want to use an array of bools, where each light has its own bool to worry about. You will probably want to give the light blueprint an integer variable, make it visible (eyeball open) and in the level give each light actor a number (your integer variable, in the details window). Then, in the logic, on overlap, get that array of bools from the save game, get the index at (Light#) and then turn THAT one on, and only that one. Same thing for loading- they’ll find their # in the array to check if they should be on or not!
Thanks! although I’m not sure what you mean by this part, how should I alter my logic now that the variable is instance editable? I’m quite new to UE5 so I still don’t understand a lot of stuff
Making a variable instance editable means that the said variable will now be publicly editable on the instance of that Blueprint. Now what you will want to do is that set the default value of the said Boolean to False. And add a Sphere collider to the Light Blueprint, whenever player overlaps with it, it should set the Boolean to true and then you can make another logic based on that if the Boolean is true, then the light should turn on.
Try it by yourself, if you still can’t get it to work then let me know, I will post blueprint images for you later.
I haven’t because of what I have experienced so far which is the following…
Add BP_Light to game world, duplicate BP_Light in game world
Code in BP_Light Event Graph waits for player to overlap BP_Light before activating
When player overlaps BP_Light (1) it turns on but it does not turn on BP_Light (2)
Which made me think, okay they are by default their own entities despite being the same BP_Light EXCEPT for when it comes to loading the level, the logic changes and activates all of them so I’m trying to work out why this is, how it can be used etc as I expected UE to be able to handle that instead of creating a Boolean for every BP_Light copy
As I said, I’m new, so I have no idea about these things, but it did seem like the logic was already on display by default, just not when calling it after loading
You have a single BP_Light blueprint in the content browser
Multiple BP_Lights in the World
Single SaveGame with a single boolean variable for On/Off
Expected behavior :
You want to save each light’s On/Off State in the SaveGame
On BeginPlay each light in the world checks the SaveGame to see if they were On/Off
Only Activated Lights should turn On.
Am I correct so far?
If so, you will need to keep track of the On/Off State of every BP_Light in the world. For that you’ll need a Boolean Array variable in the SaveGame. And an Integer variable in BP_Light to keep track of it’s Index in the Boolean Array (This integer needs to be Instance Editable, and in the world, each BP_Light’s ID should be set to a different number).
Then on begin play, you load the SaveGame, get the boolean array, loop through it, check if the loop index is equal to BP_Light’s ID (The instance editable Integer variable we created earlier), if so use the Bool value at that index to Activate/Deactivate the BP_Light.
UE does have the ability to Serialize variables in each blueprint without adding everything to a SaveGame blueprint, but it’s a lot more complicated. Also you have to use C++ as far as I know.
Here’s an example (I wouldn’t recommend doing this if you’re just starting out)
You will probably want to rename those. Maybe “Light Index” and “Light Power Array”. You definitely NEVER want variables to have the same name.
You’ll want to use the node “SetArrayElem”.
You’ll GET “CheckLight(bool array)”, pass that into the array pin.
Then GET “CheckLight(integer)” and pass that into the index pin. That tells the array which bool to switch.
Then on the final pin it will be a checkbox, so you can set it true or set it false.
After doing the SetArrayElem, SET “Checklight(bool Array)”
Pretty close- and now that I’m looking at it I think the “SET: LightArray” might be pointless because SetArrayElem is already doing that.
The only thing is the “Target:self”. That for sure isn’t right. Where are you holding the light array variable? GameMode would be my suggestion- don’t put it on the Level Blueprint. You could also use GameInstance. Wherever you’re holding that variable, THAT needs to be the target and then the rest of it on the actor.
Is SaveGame BP your save game object? If so, that’s a totally legit place to keep it! It’s a little bit harder to reference but going off of your previous thread with ClockworkOcean you know a thing or two about getting it!
sorry I’m really confused as to what to do, no matter where I put this Light Array it always calls for a target and I’m not sure how to actually trigger this event in the first place and if that’s even all I need to do?
This part.
The target part isn’t wrong, the target SELF part is wrong.
This should be on the light actor. Wherever you were turning the bool on and off before, replace that with this and have both targets be GetGameMode-> Cast to (whatever your game mode is called) → Target.