[UMG] dynamic widget communication

hi !
i have created a main widget ui containing a (multiline) text box.
during game play i create buttons. how do i target the text box of the main ui from those dynamic buttons ?

attached graph from the button

Here are solutions using custom widget class for buttons.

  1. Go to your main widget ui, go to designer mode and select your text box.
  2. In upper right corner of details panel, you should tick a is variable checkbox. You may also name the variable that will hold this widget. The field for this is on the right (or left, don’t remember :p) side of the checkbox you just ticked.


Now you can choose whether you want an ugly way or a clean one.

The ugly way.

A.3. Go to your button widget class and make variable that will hold reference to your main widget. A text variable that I used is just for testing so you can ignore it. Here’s the setup:

A.4. Go back to your main menu, and adjust your logic related to creating buttons and fill the main widget variable. Like so:

The clean way.

We’ll use use event dispatchers for this solution.

B.3. Go to your button widget class. And create event dispatcher. I called it OnChangeTextRequest and set it up as the pic shows.

B.4. Then again, we have to alter your logic related to creating button widgets. Here’s the example.

perfect ! i went the ugly way.
is there a reason why one way is considered uglier than the other ?

may the flying spaghetti monster bless your node links ! noodles :slight_smile:

It’s ugly, because other widgets are directly playing with widgets that doesn’t belong to them. Ideally when you have a widget/class A, and couple other widgets/classes like B, C, D and they aren’t meant to modify only their own stuff so the actual owner of property/widget/anything controls how it changes.

So for example instead of directly accessing text widget from buttons, it would be a bit easier to have a function in main ui widget that takes as input Text you want to put in text block and you’d call that function from buttons.

i see; thank you for taking the time to explain :slight_smile: