Global variable to control all Lights?

Is there a smart way to make a global variable that controls all lights?
If I were to cause all of the lights on a level to turn on and off on occasion should I just make an array to cast to each light or is there a way to bind the lights to something one master switch?

What is the least processor intese method for doing this?

Hey @TinyTracker1!

The best way would probably be to go into your level BP, make an array, and add all your lights in the level to that array. Make sure they all have the same parent class that has a “Light switch” variable so you can make that the base and not have to cast to each type of light (Casting only makes something act as a more specific version).

Then, as part of the level, you can run a Custom Event to grab that array and “ForEach” body-> “turnOff” Function. For style points, you can have a variable on each that says whether it was turned off before, and save that value, then after a bit, tell each to turn back on or don’t based on that variable!

Would an event dispatcher on the level blueprint over complicate this?

I would say an event dispatcher wouldn’t be any more or less complicated. That’s already pretty similar to what’s going on :slight_smile: You would do everything the same, just after the “ForEach” you would run the dispatcher message after each body.

1 Like