How to bind a Slider UMG to a variable from another Blueprint?

Hi everyone,

I’m currently developing an application for architectural visualization and I’m struggling so hard with a question about programming my UMG on screen.

The thing is: I downloaded a day/night cycle in the market place and I set it up. In game it is changable with a variable which controls the rotation of the sun and the moon. I created a Slider in order to control that variable with the mouse cursor. So I just want to know how to bind this variable to the Slider in order to make the user be able to control the cycle ingame.

I have two Blueprints: One for the UMG were the slider is placed, and another with all the day/night cycle programming.

Now I’ll upload some screenshots of the most important parts (I think they are) in order to solve this.

As you can see here, I set up a OnValueChanged function for the Slider, and with this I get to change the value of the slider with the mouse, but not the value of the variable I need.


249809-
Here you see I created a function where I scaled the range of the slider between 0 to 2400 (the cycle range controlled by the variable I need to dynamically change also goes from 0 to 2400).

And finally, here’s the variable I need to change. This is the Blueprint from the Day/Night cycle I downloaded at the Marketplace. I think it’s the most relevant part of this blueprint but I don’t know if it’s even needed to just know how to change with the slider a variable from another BP… right?

Thank you so much in advance for any help, everyone!!

I have two Blueprints: One for the UMG
were the slider is placed, and another
with all the day/night cycle
programming.

Do you need to have this slider in a separate actor? Why not create the widget in the Day/Night cycle actor?
Just asking, you may have a very good reason to keep them apart.


Generally speaking, it’s a matter of obtaining a reference. You need a widget to gain access to the Day/Night actor and make the widget’s slider set Day/Night actor’s variable.

  • where do you create the widget? (in a separate actor, framework class, level blueprint)
  • where do you create Day/Night cycle actor? (manually placed in the level or you used SpawnActorsFromClass node?)

Hi Everynone! Thank you for your reply!!

I just got to the office so I couldn’t answer earlier, apologies!.

I need the slider in a separated actor from the night/cycle, because I already programmed the UMG of the app separately with other simple functionalities.
So I created the slider inside a Widget blueprint I made for a Minimap in this project, so I thought the best way could be to just include the Slider inside the same canvas where I have the Minimap.
The Slider is working fine and it gets the values I need (in a range from 0 to 2400) but I just need to ‘‘Bind’’(?) these values to the day cycle variable (it’s name is Time Of Day, you can check it out in the last screenshot), that it has the same value range, from 0 to 2400.
This variable is created inside another whole Blueprint Actor just focused on the D-N Cycle programming etc.
So whenever I change the value of the Slider, I need to change the Time Of Day value as well, in order to make them have the same value all the time (that’s why I tried to make it work through the Event Tick in the Day Cycle Blueprint, by getting a reference to the Widget Blueprint).
I kept trying this stuff today, and now I have it like this:

Okay, both images are form the DNCycle BP. The first image shows how I now have the set up trying to get the Slider Value with a reference to the Widget.
I pluged it to a IsValid node because I wanted to check out if it’s getting it or not. You can see is not valid, so, in the second image, I tried to Get all Actors from widget but still is not working, so I’m not sure if I’m going in the right direction on this…

Just in case it’s necessary, I notify the Slider Widget blueprint still being the same as yesterday, I changed nothing! So you can check it out in my previous screenshots as well.

Thank you sooo much again Everynone, I appreciate your help!!

Ah! And I create the Day/Night cycle actor by placing it manually into the level!

I need the slider in a separated actor
from the night/cycle, because I
already programmed the UMG of the app
separately with other simple
functionalities.

Makes perfect sense.

Ah! And I create the Day/Night cycle
actor by placing it manually into the
level!

Ok, that’s the important part. You can use GetAllActorsFromClass to obtain the reference providing you will never have more than one FloorPlan. From the Found Widgets pin Get 0 element instead. This will work but it’s not a good solution in the long run.


So I created the slider inside a
Widget blueprint I made for a Minimap
in this project, so I thought the best
way could be to just include the
Slider inside the same canvas where I
have the Minimap.

This is the second piece of the puzzle - where do you create the Minimap? We’ll need this info to connect the widget and the day cycle actor together. Once we get access to the Minimap, we get access to the slider as well.

It worked!! I just used Get all Widgets Of Class and passed them through a ForEachLoop node (as you said by getting reference to the Minimap-Slider Widget is enough!), and now the reference is valid and it worked!! So simple! I can now control the cycle variable nicely!!

Once again Everynone THANK YOU! you were so nice and helpful mate, I’m checking this question as resolved!

Cheers!! :slight_smile:

Glad to hear you got it to work but you can use Get node instead of ForLoop. A bit simpler.

Also, this is a ham-fisted approach that will get you in trouble eventually. :wink: Again, if you only plan to have 1 slider, you should be fine…

Good luck with the rest!

I changed to the Get node to follow your recommendation. I’ll have it in mind!

About the case if I wanna try getting more than one slider on screen, what should I have in mind or what should I change to get it working?
No plan to do it yet but in the near future probably I would need it.

Thank you very much again Everynone!

It sounds overly complicated but super interesting to know! And doing it would make loads of work easier right? I wanna know!

I think I get it! Okay, I created the Minimap (so you mean adding the Widget to the viewport?) in the FPCharacter, in the Event Begin Play node by Creating the Widget and Adding it to the Viewport.

Again thank you so much really!!

Where do you create the Minimap? We’ll need this info to connect the widget and the day cycle actor together. Once we get access to the Minimap, we get access to the slider as well.

Once you know which blueprint creates the minimap you can ask the DayNightCycle to fetch the blueprint, which can fetch the minimap widget, which can fetch the slider. :slight_smile:

I know how it sounds. Overly complicated but it’s done only once.


You can use what you’ve got for now, once you need something more advanced, feel free to post a comment here or start a new thread.

This is simple after all!! and so well explained!
I just changed it to make it like this.

So I just set it up like this as you did.
Super easy to understand! I think this was some stuff I didn’y really know how to work with but it’s quite simple!
(I used a sequence because I’m not sure if it’s okay to do it together with the other stuff)

You Everynone rock !! Thank you once again!!

First of all, you need to store the reference to the widget in the actor that created the widget:

From now on, if you access the character blueprint, you’ll have a ready reference to the widget.

In your DayNightActor do something like this on BeginPlay:

This will take the minimap reference from the character and assign it to a variable in the DayNightActor. So you do not have to cast every time you want to use the widget.

If your widgets are more complicated (widget creates another widget inside), you will need to ensure that every time a new widget is created, you store the reference as in pic 1.

Yup. Looks good. Now you can get rid of the GetAllActorsOfClass, too :stuck_out_tongue_winking_eye:

If you ever need to create more sliders, it’s a matter of creating more variables to store their references.