# Widget slider to control light

**URL:** <https://forums.unrealengine.com/t/widget-slider-to-control-light/458723>\
**Category:** UI\
**Tags:** slider, unreal-engine, Lighting, Widget, question\
**Created:** [November 22, 2019, 3:14pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723 "2019-11-22T15:14:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 22, 2019, 3:14pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/1 "2019-11-22T15:14:17Z")

</div>

Good morning. I’m wondering if it’s possible to use a slider on a widget to control the intensity or color of a light in a material. So for example if I had a material with a scalar parameter or a 3color vector in the emissive, can I control that parameter with a slider, somehow? I’ve seen similar things done (eg. position of the sun) but I couldn’t find anything on how to achieve specifically what I need. Appreciate any guidance!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 22, 2019, 3:56pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/2 "2019-11-22T15:56:22Z")

</div>

Yes, it’s a common setup:

- create a material with a param
- create a dynamic material based on the above
- create a widget with a slider
- use slider’s _On Value Changed_ + _Map Range_ to feed the parameter value to the dynamic material

Which part of this are you finding problematic?

* * *

One way to do it:

 ![292846-annotation-2019-11-22-160733.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/2/8/3283952a822520411a35f8ef6e776b40b8a6d2ab.jpeg)

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/8/4080c20ba0da83bb9da98ce9f0034d63ad2291fa.gif)](https://gyazo.com/5e3984ba947f29b7f83872df4dd98498)

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 22, 2019, 9:28pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/3 "2019-11-22T21:28:51Z")

</div>

So the problem I’m having is just how to get all that into my BP. The material with parameters is mapped to a static mesh (SM\_Essence\_LightKit). The widget is named “controls”. I already have the “close” button set up (thanks to one of your earlier solutions!), but I’m going to ideally set on/off button, and temp and intensity sliders. I don’t understand where the functionality for the sliders would fit into my current BP, or if I need to cast to the widget each time. I’ve attached some screenshots for context - any advice would help (again!). Thanks so much!!

 ![292854-widget.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/c/19c0131c77c1ec371d880d5ee9c9785ca7b011a7.jpeg)

 ![292856-material.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/b/a/3ba6c4ffc714d3151c6203da2c91cff819b8cbaf.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 22, 2019, 9:46pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/4 "2019-11-22T21:46:28Z")

</div>

You’d need to describe what you’re trying to achieve. In my screenshot you can see how it can be self contained in a single actor.

What’s the big picture here?

Or at least see if you can answer these:

- what’s up with the mesh - placed in the level manually, part of an actor or spawned dynamically?
- where does the mesh get its material assigned / updated
- what’s the relation with the widget & mesh - is it a 1:1 ratio, 1 mesh + 1 widget and that’s it or…?
- does each mesh have its own widget or one widget controls more meshes’ materials
- are you going to have more than level (otherwise you can do some stuff in the LB directly)

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 22, 2019, 10:26pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/5 "2019-11-22T22:26:16Z")

</div>

Yeah, of course.

_what’s up with the mesh - placed in the level manually, part of an actor or spawned dynamically?_  
The mesh is part of an BP actor, placed in the level. It’s basically a light that attaches to a product. Should mention, this is a Magic Leap project.

_where does the mesh get its material assigned / updated_  
The material is assigned directly to the mesh - there are 3 materials for this particular mesh, and the “light” that I need changing is element 0.

_what’s the relation with the widget & mesh - is it a 1:1 ratio, 1 mesh + 1 widget and that’s it or…?_  
1 mesh, one widget. The plan is that when the user points (overlaps) the light, that widget pops up and can be used to control the light intensity etc. Then there’s a button to close.

_are you going to have more than level (otherwise you can do some stuff in the LB directly)_  
There are multiple levels, but they are all very separate. This level won’t have any effect on other levels, and this product is the only thing in this level, so I imagine the LB is fair game 🙂

Thank you!!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 22, 2019, 10:33pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/6 "2019-11-22T22:33:51Z")

</div>

> The plan is that when the user points  
> (overlaps) the light, that widget pops  
> up and can be used to control the  
> light intensity etc. Then there’s a  
> button to close.

So the object is what triggers the interaction, right? You hover / click the object, widget pops up and it controls the selected object?

In that case create the widget inside this object, exactly how I’m doing it. Each object has its own widget. That should work, no? Hitting close should remove the widget from the parent, conserving memory.

There are other ways but that would be a tad more complicated. You could have a single widget that dynamically hooks up to whatever object was most recently selected. Probably a better approach from the memory management point of view - not sure how critical it is; it probably is as Magic Leap is pretty cutting edge.

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 23, 2019, 12:23pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/7 "2019-11-23T12:23:08Z")

</div>

I seem to have this all working, apart from one thing - the slider that controls the light temperature. So basically it’s a color slider that will graduate between two pre-defined colors. I have tried using two vector parameters and flip-flopping them, which will give me the color change in a very binary way, but I need the slider to graduate and represent all of the colors in between. Does that make sense? Is there an easy way to do this? I really appreciate your help @everynone

 ![292878-widget.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/4/b9439f2c299fcc8c8de372aabd307ac0d216724e.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 23, 2019, 12:38pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/8 "2019-11-23T12:38:10Z")

</div>

The _colour accurate_ node is called `Lerp Using HSV` - feed Alpha slider value.

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 23, 2019, 12:52pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/9 "2019-11-23T12:52:56Z")

</div>

And how do I feed that value back into the DMI?

 ![292879-hsv-return.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/2/db2e8d5c9d451519473e7dd13b4d15159c1771f0.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 23, 2019, 12:56pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/10 "2019-11-23T12:56:59Z")

</div>

The same as before, the object that has the DMI created the widget so it has all the hooks. How did you connect the one with the light intensity?

Or you’re doing things differently here?

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 23, 2019, 1:12pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/11 "2019-11-23T13:12:31Z")

</div>

Yeah, I went off on my own messy tangent - I couldn’t figure out part of your BP example for creating a widget. I couldn’t figure out what you were plugging into the return value of the create slider widget. Here’s my current BP, I am certain that it’s highly inefficient and laughable 🙂

I’m just struggling through here!

 ![292881-currentbp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/d/7/bd79857b1f06c5cbbd60886103fc147eb3298a63.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 23, 2019, 2:08pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/12 "2019-11-23T14:08:30Z")

</div>

> I couldn’t figure out what you were  
> plugging into the return value of the  
> create slider widget

It’s just a variable that stores the reference to the widget - you should (almost) always do it. Right click the return value pin of the create widget node and promote to variable. You can now use that reference to access the widget directly; what’s more, other actors can now use that widget’s reference as well.

So where is the DMI (which you should also have a variable for, btw) for this temperature slider?  
I am assuming it’s a different one than in the attached pic, right?

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 23, 2019, 5:28pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/13 "2019-11-23T17:28:26Z")

</div>

The same material (M\_ColorShift) holds a parameter for emissive color and emissive amount. Should that be split into two separate materials?

 ![292884-mat.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/e/7de768d7d3ab65d7123e1807c5c9669a6e71ad39.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 23, 2019, 5:51pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/14 "2019-11-23T17:51:49Z")

</div>

No, no, that’s absolutely fine as is. Just feed the _DMI_ the vector parameter from the _Lerp_ node. You’re already using scalars, this time round use a vector param.

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 25, 2019, 5:06am UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/15 "2019-11-25T05:06:34Z")

</div>

@everynone - I feel we’re so close! I’m not getting a color change when I move the slider… am I hooking this up correctly??

 ![292935-lerp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/d/6dd2cebfc6f8d8e6b87992f67e4d5ceeac58a4ac.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 25, 2019, 6:51am UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/16 "2019-11-25T06:51:00Z")

</div>

Connect the event execution pin instead. It’s disconnected. If in doubt compare the execution flow in the onClicked events with the Scalar param.

Moving the slider fires onValueChanged\_Temp.

 ![292936-untitled.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/c/01c323870c9913336af05c54c0b0fa2073ab5ad7.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 25, 2019, 7:36am UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/17 "2019-11-25T07:36:13Z")

</div>

There’s also a couple things you can do to reduce the spaghetti; it’s optional but makes it easier to read and debug scripts at times. For example:

 ![292937-annotation-2019-11-25-073302.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/d/b/2db012fb37a2b19b3758afdc78df2860f4650a53.png)

---

<div class="post-metadata">

**Author:** ![replica101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@replica101](https://forums.unrealengine.com/u/replica101)\
**Post date:** [November 25, 2019, 1:06pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/18 "2019-11-25T13:06:30Z")

</div>

@everynone - you’re a legend, thanks for saving my bacon once again 🙂

---

<div class="post-metadata">

**Author:** ![vancuoc29](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vancuoc29](https://forums.unrealengine.com/u/vancuoc29)\
**Post date:** [August 28, 2022, 1:07pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/19 "2022-08-28T13:07:09Z")

</div>

Hello bro,  
How can I find this one?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/8/6b89086a8322cbab6646e5821a824b98a7251d40.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 28, 2022, 1:17pm UTC](https://forums.unrealengine.com/t/widget-slider-to-control-light/458723/20 "2022-08-28T13:17:27Z")

</div>

You don’t find it. You create a reference variable and name it. Right click the `Return Value` pin and promote to variable.
