Download

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.

33d5d03792a279a69228db016d0591a4b7601767.jpeg
Location in scene
8324cdd63fe9580bae0bbec8878bf00bb3c22967.jpeg
Lightswitch blueprint setup Name: LightbuttonBP


Spotlight Blueprint Setup Name:Pointlight2

439bb932df2af0e5dbe4aa5a0cbfbc9e3d91773e.jpeg
Script for pointlight2
ffe3309c1dae99fa62105aa202eea0e391831af1.jpeg
Script for LightbuttonBP
5e8c352da2fde8756442d1b216f2875d655e3b59.jpeg
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!