Slider Widget

In widget blueprint I have a slider. And in level blueprint I want to use the value of the slider. How can I access the value of the slider from level blueprint?

Think of the blueprint that created the widget - you’ll find its reference there (if you stored it).

I created the widget in widget blueprint. And I can use slider’s values in that blueprint but I need to use it in another blueprint. Could you explain it more detailed please?

No, where did you use the Create Widget node and added it to the Viewport? - that’s widget creation, I’m talking about the widget designer at all.

I used the Create Widget and added it to the Viewport in level blueprint too.

I see. Level Blueprint created the widget - generally not the best method as it’s somewhat notoriously difficult to obtain reference stored there. Do you absolutely must do it in the LB? Is this something that will exist only in this one level?

And which blueprint needs the data from the slider? If the other object is also in the level already, it’s super easy. If it’s spawned dynamically, it’s a bit more complicated.

Generally speaking, you always want to create a reference to the widget so you can gain access to it later:

That’s the first step.

Actually the game I thought of is a one level game like HOI IV but I am new to the engine so I am just trying to explrore there is no musts for me now.
By the way I managed to access the variable from the level blueprint. Thank you for your help.

You’re welcome - if both elements are in the LB, it’s super easy, true.

I thought I managed it but I didn’t. I used “cast to” to access the variable which is in “widget blueprint” from “level blueprint”. Now I can access to variable but I can’t compile because it asks me an object.

Can’t see the image, this service is not working for me.

That’s precisely what I was talking about, you can’t cast to Level Blueprint. Create the widget in the player character, game mode, player controller - any of the framework classes. You’ll be able to access them those from anywhere, including the LB.

I changed it. I created the widget in the gamemode. But I still can’t use “cast to”.

Is the above actor (NewBlueprint2) the GameMode that you’re using? If yes then:

  1. What you’re doing here makes little sense - you’re trying to access a widget that you already have here…
  2. Have a look at the image I attached below - you’ve yet to create a reference for your widget
  3. Casting should be now done in the LB which is going to access Game Mode that has the Widget Reference - you wanted to access the widget’s slider in your Level Blueprint, right?

Once you’ve dealt with #2, in the LB Get Game Mode → Cast To YourGameMode → get your widget → get your slider.

Casting is not a magical way of gaining access to data, it’s just checks what kind of actor it is, to simplify it greatly.

edit: here’s the whole setup:

I did #2. And after that in Level Blueprint I got gamemode and cast to the gamemode that I created the widget in. But I can’t do the rest.(get your widget → get your slider)

Is your custom GameMode a GameMode? See the pic with wavy arrow, above it:
ParentClass: Game Mode Base

Is it assigned as your game mode? The end of the wavy arrow.

Yes it is assigned as my game mode.
I managed to got my slider now. But I can’t get values of slider and assign the values to a variable. Maybe casting is not what I was searching for. Anyways good to learn these about casting but how can I solve the variable issue? :frowning:

Everynone is correct about generally avoiding the Level BP to create anything that you will need to reference later as it is difficult to access. Also true that you should create a reference to your widget right after you create it for easy access and use later. That being said, your solution is simple. Since you create the widget in the Level BP and want to access a variable within the widget FROM the Level BP you don’t have to do anything more than connect the Return Value of the “Create Widget” node into the “object” pin of the cast node. So if you go back to your screen shot and simply drag out from the “create widget” return pin and plug it directly into the missing object pin, everything will compile.

** In fact, you don’t even need the “cast” node since the created widget is already of the desired type.

You’re almost there!

252371-untitled.png

What is that OnValueChanged node doing in the LevelBlueprint?! How did you even do that? :slight_smile: Copy & paste?