Creating a simple Light Switch in blue print Visual Scripting

Hey there,

I’ve been asked to do some research over the past week in Ue4 for Archviz. I’ve been focusing on Lightmaps and getting those right.

Now i’m moving on to some interactivity aspects with regards to Arch viz, interiors, such as using keyboard control to switch lights on at a light switch location.

As i’m new to visual scripting and C++ i’ve stumbled across a problem with how my script works.

I’ve followed this post to create my switch, but it doesn’t execute, turning the light on and off. I was wondering what i am missing. If anyone can help or point me in the right direction that would be great.

Original post i followed, i have used AceD’s method as i think this is what i am after.

I want to walk up to the light switch, when in close proximity, i want it to show the letter E, then when i press E on the keyboard i want the light to turn on, Then press E again and it will turn off. When i move away from the proximity of the switch the E will disappear.

Here’s some information of what i have set up so far and for the purpose of simulation i walk to the light switch and press E and this is how far it goes it cast fails.


Location in scene

Lightswitch blueprint setup Name: LightbuttonBP

Spotlight Blueprint Setup Name:Pointlight2


Script for pointlight2

Script for LightbuttonBP

Simulation of where it gets up to

This doesn’t work because you have to choose the “ActorClass” in the “GetAllActorsOfClass” node to “MyWallsonceBP”. But anyway, this isn’t a nice solution because this way this will only work when you have exactly one “MyWallsonceBP” instance in your level. A better solution would be to add an editable variable of type Reference to “MyWallsonceBP”. When E is pressed you will then call LightSwitch on that variable. An IsValid node before that call would also be smart. And in the editor you manually select the reference to the respective “MyWallsonceBP” instance in each instance of your “LightButtonBP” instances. That way you could have as many switches and lights in your level as you want.

That’s great, adding mywallsonceBP to the get all actors of class turned the light on :). Progression!

Your other part of the message sounds interesting, but unfortunately i don’t have the knowledge to follow what you mean :(. Maybe if i get a bit more understanding of visual scripting :slight_smile:

Thanks for your respons though Pepeee, great help

Hello Myattc,

I think Pepeeee means, like you did with adding the “Brightness”, “Color”, “Inner Cone Angle”, etc. variables to your LightbuttonBP blueprint, you would add a new variable in that blueprint, but instead of it being a float or bool or whatever, you would search for MyWallSconceBP. It’ll have to specify the type of that variable, and you’d select “reference.” Make that variable public, then when you select the LightbuttonBP blueprint in the level, you can assign the value of that MyWallSconceBP variable to a physical instance in the level.

This means that anything you do to that variable in the blueprint, will affect that specific instance of the “MyWallSconceBP” you selected in the details panel.

Hope this helps!