Toggle Light from UMG Blueprint

Hi folks !

I would like to Toggle a light from a button created in UMG blueprint but I don’t see anything in Blueprint that refers to my light.
I don’t see how to make it works.

Could you help me?

Thanks a lot

Hi Denis,

is the light for the player character? Like a flashlight?

If it is, create a custom event in your character blueprint called “Toggle Light”, then grab your light component and reference it on the graph, drag it out and type “toggle visibility”. (Hint: make sure to compile your blueprint!)

Then open up your widget blueprint, create a on clicked event for your button.

Then proceed by right clicking > get player character. Then drag the player character out and cast to: my character (or your character blueprint name). Then drag out the “as my character c” (small blue output pin), then type in your custom event “toggle light”.

Hope this helps!

Hi Tesla ! Thanks for your answer and I would like to say that I love your tutorials ! :smiley:

No I’m just trying to toggle a simple light in a room with a UMG button. Is the process really different?

Thanks! No it shouldn’t be. Here’s one way to do it.

If it’s just a simple light in your map (and not a blueprint) Try this, this is a process for a level blueprint.

In your widget blueprint, create a on clicked event for your button. Then add a event dispatcher “click the two arrows to the top left next to functions & macros”. Then name it Toggle Light. Drag it out onto the graph and hit call. (Make sure the event and call are connected). Hit compile and save.

Now in your level blueprint, get a begin play, Create your widget, choose the widget. (connect the begin play and create widget together) Then drag out the small blue output pin “as my widget c” and type in

  1. Add to viewport. Connect that to the create widget (show your UI shows when you start the game)
  2. your event dispatchers name. (toggle light) Then get the top one which should be “assign toggle light”.

You should now have two nodes created, a blue one (function) and a red one (event).

Make sure the blue one is connected straight after your create widget and add to viewport.

Now find your light in your map, select it, right click in the blueprint and get a reference to it. drag it out and type in toggle visibility. Then make sure the red event is connected to the toggle visibility.

Should work… i think…

It worked like a charm ! :smiley: Thanks a lot Tesla ! You rock! :wink:

Hello Denis and Tesla,
I need some help for something similar I’m doing for my thesis.

I’m trying to show a button when the player overlaps a trigger box and then when the user press the button I want to change some materials in the game. At the moment I can change the material by pressing “7” on my keyboard and everything is ok, but I would like to do it using the button. I’ve tried to follow instruction above to connect my button but I can’t go on at this point:

“2. your event dispatchers name. (toggle light) Then get the top one which should be “assign toggle light”.”

because I can’t see my event dispatcher called “ChangeMaterial” in the list. Maybe I’m missing something…

Thank you for your help



Hi Tesla.
I have the same issue with a widjet button which once is clicked by mouse turns on/off a flashlight. I read your istructions until “get player character”. I can’t go on when you said “drag the player character out…” and so on.
I have updated two screens. 1) is the flashlight into character blueprint. 2) Is the widjet blueprint with the “torcia” button and player character. Can you help me? There is somewhere a documentation about ? thanks
http://s12.postimg.org/9eii7iyzh/Graph1.jpg
http://s14.postimg.org/84qmaetg1/graph2.jpg

Ok I am very stupid. For anyone who needs I have updated the blueprint screen which i resolved the issue.
http://s27.postimg.org/yl3kxx2ib/Graph3.jpg
HTH