Casting from a widget to another

Hey guys! I was hoping you can give me some light in this. I want to set a variable stored in a widget from another widget. I’m using the casting node as it never gave me problems with all this stuff. But what should i put in the Object pin? I’m attaching a image of the bp just in case. Thanks!

You need to specify a reference to the other widget that was spawned/created/constructed as the Object. When you cast one object to another you need an instance of the object you are trying to cast. Otherwise you will be casting NULL/NONE to something which is an error/exception.

Your Menu widget blueprint needs the reference to this other widget. Generally the approach I would take is to spawn the other widget and store it’s returned reference in a variable.

Take that variable that contains the widget I just spawned and pass it to your Menu widget as an Exposed On Spawn parameter. Now your Menu widget contains a class variable that references the other widget and it can cast/call the other widget.

1 Like

It might be helpful to share screenshots of your code that spawns the widgets.

Can you extend the instructions a bit? I’m a bit noob :I

Ok, how are you spawning these widgets? Are you calling the Create Widget node?

Yeah, the Player UI widget is spawned via Create Widget node from my player blueprint and the Menu one is spawned with the same node from a level blueprint

In the PlayerController, spawn your two Widgets, store each Widget in a variable. When you spawn your Widget that needs to talk to the other one, pass a reference to the other one during Create Widget.

This is my Player Controller.

WB_InputTextBox is a simple widget that only has a Textbox that is set to be exposed through a variable named “TextEntered”. Our other Widget blueprint will call our TextEntered to get the text that was typed into the input box.

WB_TextEntered is a Widget that has two text nodes. One text node is hard coded and the other text node has it’s text value set to the value entered into WB_InputTextBox’s TextBox node.

During the tick event for the WB_TextEntered widget I get the value that was typed into the input box in the WB_InputTextBox.

Did my answer below help you figure it out?

I solved it moving the variable and it’s related system from the widget to my character. I don’t know why i chose the widget as storage. Thanks anyway for everything

Glad you figured it out.