Communication between 2 UI Widgets

Hello!

I’m new in Unreal Engine and in this Forum.

I’ve attached 2 screenshots just so to understand how UI works.

I want Widget A to get the value from Widget B and then updates the value of A with the new value. Widget A only contains 1 variable “A” having a value of 0. Widget B only has a variable called “B” having a value of 5.

I want to know how I can make them communicate with each other so that when I press the button the value of the A changes to the value of the B.

Note: I’ve watched several videos on the Internet about having a third person character or first person character and then “Cast to” and all. But I don’t have those. I wanna know how to pass a variable when there is no First Person or Third person character.

A help will be greatly appreciated.

Edit: I cannot send more than 1 screen shot so the Widget B looks the same just without the button and has B = 5

You can use event dispatcher inside your widget that will be triggered when you update your value text.
If you created your 2 widget inside your player controller, you can (bind) your event dispatcher using thier reference. (or a similar way, this was just an example on how you could use event dispatcher)

1 Like

As above. You’d (we) need to know where those widgets are.

  • where, how and when are they created?
  • are they nested inside one another?
  • created by a component?
  • in different actors?
  • one is created in level blueprint and the other elsewhere?
  • perhaps one widget creates another?

By default actors / widgets do not know about each other’s existence. Your job is to tell the editor where things are and hook them up.

So - how, when and where do you create both widgets?

This is the flow:

The level starts with level blueprint creating both Widget A and B but only adding Widget A to viewport shown in the 1st photo. In Widget A, I’ve created a Event Dispatcher like the 2nd photo. Then in the third one (Widget B), I’ve created a bind to the dispatcher to just print a statement “Hello” for now.

I’ve trying to use this “Cast To” with countless tries for a while now but it always comes down to this specific error you can see in the 3rd photo. That doesnt accept any input in the “Object” reference. I’ve tried linking “Player Controller”, “Player Character” and “Pawn” but it still shows Error.

Also tried creating the Widget A in Player Controller, it being a reference to Widget A and then tried to link with the “Cast To” node but this error doesnt go away.

Ideally, you’d reference the widgets first. Since both are created in the LB, use the dispatcher to bind their events, send data.

Do it in the LB, not inside the widget.

There’s no need to cast here at all.

Widget A:

Level BP:

1 Like