Hi, I have created a blueprint for switching on and off a light. I have followed a tutorial and then I have decided to create 4 lights, but I don’t know how to modify this. I mean I know there are other tutorials on Youtube, but they do other methods so I’m confused, I 'd like to go on with this.
So the first step is duplicate 3 times the ‘light’ button, and then?
I have read this comment on Youtube but honestly I don’t understand, because I’m learning by watching videos (yes, I’m a mess):
First, duplicate the light component and name the two components Light_01 and Light_02.
Now, after the branch, attach to the “True” output a node called “Sequence” (this type of node allows you to activate multiple actions from a single input).
Branch, Output True - Sequence
From the Output “0”, add a Print String: “On_01” - IsLightOn (checked) - Set Intensity (use Light_01 as the target) with New Intensity = 10 (for example).
From the Output “1”, add a Print String: “On_02” - IsLightOn (checked) - Set Intensity (use Light_02 as the target) with New Intensity = 5 (for example).
Now from the branch, but at the False output, attach another Sequence:
From the Output “0”, add a Print String: “Off_01” - IsLightOn (unchecked) - Set Intensity (use Light_01 as the target) with New Intensity = 0.
From the Output “1”, add a Print String: “Off_02” - IsLightOn (unchecked) - Set Intensity (use Light_02 as the target) with New Intensity = 0.
Hi, The reason it isn’t recommended to do it this way and why youtube videos would use other methods is because it’s not modular, each time you want a switch to control a light you’d need to add it in blueprints like the way you’ve described.
The simplest way to adapt what you have to control multiple lights would be to change your Light Object variable into an Array of Light Objects and expose on spawn.
Then in blueprint:
Get LightsArray-> For Each Loop (Connected between print string and Set Intensity) → Drag Off Array Element → Point Light Component → Set Intensity.
Then in the editor focusing your light switch, with the LightsArray you can add the lights you want your switch to control by adding an entry to the array and using the eyedropper tool to click on the Light Actor in the editor.
This method would allow you to create clusters of lights that a switch controls.
Another method would be to use a Delegate, especially if you want the switch to control all lights. I would recommend learning about them.
For a simple multi light (2-4) setup would have all the lights and switch in the same class. The drag the actor in, move each light to its position and move the switch. When the switch is toggled it can talk directly to all the lights.
For more lights use an event dispatcher in the Switch class. Then create a class for the light. Next have you Light BP’s simply create a bind to the switches dispatcher event(s). This approach can be used for 1-1000+ lights on a single switch.