x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.20
Tags:
more ▼

asked Sep 01 '18 at 11:57 AM in Blueprint Scripting

avatar image

TheMurtcnn
6 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Sep 01 '18 at 12:08 PM

avatar image

Everynone
14.8k 77 25 62

avatar image TheMurtcnn Sep 01 '18 at 12:18 PM

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?

avatar image Everynone Sep 01 '18 at 12:19 PM

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.

avatar image TheMurtcnn Sep 01 '18 at 12:22 PM

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

avatar image Everynone Sep 01 '18 at 12:26 PM

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.

avatar image TheMurtcnn Sep 01 '18 at 12:35 PM

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.

avatar image Everynone Sep 01 '18 at 12:37 PM

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

avatar image TheMurtcnn Sep 01 '18 at 04:39 PM

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.

[1]: https://i.hizliresim.com/Y69EEj.png

avatar image Everynone Sep 01 '18 at 05:15 PM

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.

avatar image TheMurtcnn Sep 01 '18 at 05:47 PM

I changed it. I created the widget in the gamemode. But I still can't use

68767.png (162.9 kB)
avatar image TheMurtcnn Sep 01 '18 at 05:47 PM

I changed it. I created the widget in the gamemode. But I still can't use "cast to".

avatar image Everynone Sep 01 '18 at 06:15 PM

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:

alt text

alt text

gm.png (141.8 kB)
lb.png (61.7 kB)
avatar image TheMurtcnn Sep 01 '18 at 06:37 PM

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)

avatar image Everynone Sep 01 '18 at 06:42 PM

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.

avatar image TheMurtcnn Sep 01 '18 at 07:09 PM

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? :(

avatar image TheMurtcnn Sep 01 '18 at 07:09 PM

alt text

3857357.png (291.0 kB)
avatar image Everynone Sep 01 '18 at 07:16 PM

You're almost there!

alt text

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

untitled.png (52.1 kB)
avatar image TheMurtcnn Sep 01 '18 at 07:25 PM

Not copy paste :) I drew a line to show how did I get it. It does not let me put the variable there.

avatar image Everynone Sep 01 '18 at 07:31 PM

If NewVar0 is the reference to the widget you created in the GameMode, drag a wire from NewVar0, search for AKPSlider LB (the green float).

avatar image TheMurtcnn Sep 01 '18 at 07:42 PM

Okay I managed it. Now I can access the variable in widget blueprint from level blueprint with both of your and Nebula Games Inc.'s ways. I can show it in the screen too but when I slide the slider it does not updates the variable on the screen. But if I print the variable from the widget blueprint it updates the varibale on the screen when I slide it unlike I access it from level blueprint and do the same things.

avatar image Everynone Sep 01 '18 at 07:45 PM

This method allows you to access the slider's variable from anywhere, any blueprint. Useful stuff.

But if I print the variable from the widget blueprint it updates the varibale on the screen when I slide it unlike I access it from level blueprint and do the same things.

Is the Slider's Value pin connected to the variable in the widget?

Alternatively, you can get the Slider79 and get it's value directly - both should work.

avatar image TheMurtcnn Sep 01 '18 at 08:03 PM

Is the Slider's Value pin connected to the variable in the widget?

It looks very complicated now I can't see the answer of your question.
avatar image TheMurtcnn Sep 01 '18 at 08:03 PM

alt text

27435477.png (188.0 kB)
avatar image Everynone Sep 01 '18 at 08:07 PM

Get rid of Set NewVar1, get rid of slider79, get rid of Set AKPSlider LB (this one is optional, though). They're not needed. The slim green float AKPSlider is your value here.

Go back to your widget and check if the slider event is updating the variable you're accessing. In your image with the long red arrow they're disconnected, for example.

avatar image TheMurtcnn Sep 01 '18 at 08:19 PM

I got rid of them and still the same. I can only print the first value of the slider (which is 0.0). This is the final version now.

avatar image TheMurtcnn Sep 01 '18 at 08:20 PM

alt text

7879.png (187.3 kB)
avatar image TheMurtcnn Sep 01 '18 at 08:20 PM

alt text

7878.png (113.5 kB)
avatar image Everynone Sep 01 '18 at 08:21 PM

It all looks good here. Can you show how you update the variable in the widget?

avatar image TheMurtcnn Sep 01 '18 at 08:23 PM

alt text

1212.png (31.2 kB)
avatar image TheMurtcnn Sep 01 '18 at 08:23 PM

If I add print string next to it, it works.

avatar image Everynone Sep 01 '18 at 08:24 PM

Looks fine, and this is the widget you created in the custom GameMode and assigned to the NewVar0 variable?

avatar image TheMurtcnn Sep 01 '18 at 08:29 PM

Yes, exactly.

avatar image TheMurtcnn Sep 01 '18 at 08:30 PM

alt text

2121.png (62.3 kB)
avatar image Everynone Sep 01 '18 at 08:37 PM

So the Print String code is just behind the Set AKP Slider LB, right? And what triggers the printing?

What are the chances that you're using a slider from another widget?

Grasping at straws here :)

avatar image TheMurtcnn Sep 01 '18 at 08:45 PM

alt text

4545.png (160.4 kB)
avatar image TheMurtcnn Sep 01 '18 at 08:46 PM

There is only one widget and this widget has only one slider. :(

avatar image Everynone Sep 01 '18 at 08:49 PM

So what is the default value of the widget's slider then? Or the default value of the AKP variable?

If you print this at begin play and both are set to 0, you'll see 0 printed, you surely have no time to adjust it to anything else.

avatar image TheMurtcnn Sep 01 '18 at 08:51 PM

Slider's default value is 0.0 and it changes when I slide it. AKP variable's default value is 5. And when I play the game it prints the screen 0.0. It changes the default AKP value to the sliders starting value but when I slide the slider it doesn't update it.

avatar image TheMurtcnn Sep 01 '18 at 08:54 PM

alt text

1111.png (137.3 kB)
avatar image TheMurtcnn Sep 01 '18 at 08:53 PM

This is what I am trying to do (Blue ones)

avatar image TheMurtcnn Sep 01 '18 at 08:53 PM

alt text

1112.png (531.6 kB)
avatar image Everynone Sep 01 '18 at 08:54 PM

But you just print it once, on Begin Play. If you update it later, you need to print it again. Hook it up to Tick in the LB and try again.

At the moment you just put the default value on screen for 60 seconds.

avatar image TheMurtcnn Sep 01 '18 at 08:59 PM

Yes it works now (kind of). There are still little problems but it updates as I slide the slider. Thank you :)

avatar image Everynone Sep 01 '18 at 08:59 PM

Yay!!! That was quite a ride :D

I take kindly to kind of works every day.

avatar image Everynone Sep 01 '18 at 12:31 PM

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

alt text

That's the first step.

capture.png (65.7 kB)
avatar image Nebula Games Inc Sep 01 '18 at 07:10 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question