I am trying to get a variable from a UMG widget to another using the node “Cast to”, however for some reason it always fails. Here is how the blueprint looks like:
Begin Game HUD is a reference to the other widget created manually in this blueprint, so i don’t really know why it is not being successful.
Where have you set the var “Begin Game HUD” with a value? Because if you just said to the Engine that is the same type as BeginGameHUD then the value inside of the var is null.
As you guessed, i set the variable to BeginGameHUD. So what should i put instead? I have been trying but didn’t solve this.
When you create your “BeginGameHud” with the node called “Create widget” you should save the out pin into a var, then pass that var to the widget.
This is TODO list:
- Create the widget Begin Game HUD through the “Create widget” node.
- Save the result of that node into a var
- Create your second widget(the blueprint) where you need to get access to the info of the first widget
- Create a var into the second widget with type “Begin Game HUD”
- Click on that var and check “Editable” and “Expose on spawn”
- Create the widget with “Create widget” node then insert the outpin of the “Create widget” of the point 1) into the new var
I can create the script if you didn’t undestand something
Sorry about the 6), you don’t have to recreate the widget, i just said it twice, my fault.
I created a simple example.
In the explainmore.png i show you how the var should be (It’s the second widget, the one where you need to use the cast). Explain is where i create the 2 widgets.
PS: If you still have problems with that you can send me the project and i will take a look for you
Understood all but point 6. Why do i need to create the widget again if i only need to access it. However, even when i tried doing 6), i didn’t get any node asking for a “BeginGameHUD widget” input. Could you please shine some more light on this?
Oh i see. I didn’t know why you were creating two widgets because i was thinking that the widgets would show up on EventBeginPlay, but i forgot you need to add them to the viewport. Now if i understood everything correct is that doing that the variable created can now be used to cast. I’ll try to implement this.
Yes, if you do like this you should be able to use the cast node without problems. If you have more question just ask and i will try to help you.
Allright, it is working as intended. Knowing how to cast from widget to widget will make my project a lot easier. Many thanks for spending your time to help me and for such a useful tip Davide!
No problem, glad to help. Please, accept the answer for tracking purpose. And, optionally, click like on comments.
Totally forgot about that, i’m pretty much a noob in terms of this website. Anyway already accepted the answer and thanks again!
No problem . Check only one that is labeled as " solved " , because I see it as yet unresolved .