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!
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:
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!!
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)
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
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.
The colour accurate node is called
Lerp Using HSV - feed Alpha slider value.
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?
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
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!
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?
The same material (M_ColorShift) holds a parameter for emissive color and emissive amount. Should that be split into two separate materials?
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.
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.
@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??
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:
@everynone - you’re a legend, thanks for saving my bacon once again
You don’t find it. You create a reference variable and name it. Right click the
Return Value pin and promote to variable.