How can I make a Global variable that multiple blueprints can change?

Hello! I have a blueprint that states whether or not a player is standing in light. Basically how this works is I have a point light that traces lines at the player. If the player is unobstructed and is within the light radius, it sets a variable called InLight to true and if not false. Everything seems fine until I drag multiple of these into my scene. Then one blueprint recognizes it as true and the other as false like so.

I need a way to state that if at least one of these InLight variables in any of these blueprints in the scene are set to true, a global variable of sorts is set to true. Is there any way I can do so? I’ve tried making the InLight variable public, but public isn’t the same as global so the problem still persists. Any help is greatly appreciated. Thanks. :slight_smile:

Having all these lights turning the variable on AND off is not going to work.

Instead, you could keep track of the last time light touched the player and if over the defined time period it would be set to false. Then all the lights have to do is turn the variable on.

You need an OR variable, or you can just make the variable inside of the game mode, and cast to it.

Just store that variable on the Player BP and Cast To that BP from each light to set/unset it.

If he casts from multiple lights and one is turning it on and one is turning it off at the same time then it won’t work.

Also an OR node will only work if you know how many lights can affect the player simultaneously.

A good approach, which completely avoids the necessity of any AND or OR operations is the following:

At the begin of Tick, set a global boolean variable “IsInLight” (or one within the player BP) to false as a first step.

Then go through the lights. If a light trace evaluates as “being in light”, then you change the variable to true.
If the trace evaluates that the player is in the shadow, you do… nothing…

This way, just one true light is enough to change the variable.
If multiple light are “true”, then the global variable is set repeatetly to true, but thats not a crime, is it…

Okay. I understand what you guys are saying. So I’d have an event tick connected to a sequence then set InLight variable to false. Have the second part of the sequence connected to the part of the script that actually does the line tracing and whatnot. Then in the part of the script with the booleans I only connect the parts that state that the variable is true. I’m not entirely sure if that’s exactly how to do it but I’ll get to working on it as soon as I get the chance later today. Thanks so much.

Okay! I changed my blueprint so instead of setting the variable every tick, I’d set it only when the player entered and exited the detection range of my light. That works out very well. Thanks for your help. :slight_smile:

Avoid using Tick as much as possible in situations just like this :slight_smile: