# Trying to get a variable from one widget to another

**URL:** <https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851>\
**Category:** Blueprint\
**Tags:** interface, variables, unreal-engine, Widget\
**Created:** [September 20, 2024, 2:31pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851 "2024-09-20T14:31:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 2:31pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/1 "2024-09-20T14:31:10Z")

</div>

So, I have two different widgets.

The first is a dialogue box. Its structure is like this:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/1/6f1c30b5213cf9dded5f5d6c5cb6c4a11a451f9b.png)

I have functionality where, depending on the NPC you are talking to, a number of Text Blocks get created and parented to the GridPanel.

Those Text Blocks are all based on this Widget blueprint:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/a/2/9a2b2ea5f56a8ab8af960c7099a8d3b452c1c4be.png)

I’m trying add functionality so that when one of these Text Blocks is clicked, it changes the text in the DialogueText Text Block from the first blueprint.

I have an interface to send the exec from the second blueprint to the first upon click, but I cannot figure out how to get a ref to W\_DialogueBox into W\_DialogueTopic.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/2/8/7286e37e8382b398edea8283acc43b929a556c0a.png)

I can get the parent of the parent of the parent of W\_DialogueTopic, which is the Canvas Panel in the first widget, but it won’t let me go one step further and get W\_DialogueBox itself.

I thought maybe I could just do what I need to do directly in W\_DialogueTopic’s blueprint, but in order to get the DialogueText Text Block variable, I still need a ref to the W\_DialogueBox somehow, so either way it’s a dead end.

It might be helpful to know that W\_DialogueBox is itself created in a third blueprint, an Actor Component that gets added to anything that can have a dialogue.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/e/abe1db11f6622fa5eb62aba73f58dc2ed8d2a7fb.jpeg)

I suppose I could refactor this and put some of this logic directly into the W\_DialogueBox blueprint, get a reference to self in there, pass that variable to Player Controller or something, then grab that within the W\_DialogueTopic blueprint? It seems like a lot of work for this though, so I’m guessing there must be a simpler way to get these actors to talk to each other.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 2:54pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/2 "2024-09-20T14:54:30Z")

</div>

> [@davi1521](#):
>
> I’m trying add functionality so that when one of these Text Blocks is clicked, it changes the text in the DialogueText Text Block from the first blueprint.

This is a job for event dispatchers. The description is somewhat convoluted, though - could you confirm 2 things:

- when the `Dialogue Topic` is clicked, we receive a notification in the `Dialogue Box` so it can set its `Dialogue Text`
- `Dialogue Topics` are added to the `Dialogue Box` - but where and how does it happen?

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 3:02pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/3 "2024-09-20T15:02:32Z")

</div>

> when the `Dialogue Topic` is clicked, we receive a notification in the `Dialogue Box` so it can set its `Dialogue Text

This is what I’m trying to achieve, but no luck so far.

> `Dialogue Topics` are added to the `Dialogue Box` - but where and how does it happen?

I don’t if this is enough of the logic to answer your question, but here it is (inside W\_DialogueBox):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/5/ee5d4389fc5ab7ea8c770d2d2159b199eceda7c7.png)

Each NPC has its own table that stores the dialogue topics and the corresponding text. Those tables in turn are stored in a master table. Each NPC has a variable integer that acts as the key to use as the look up to pull the index corresponding to the npc’s table.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 3:15pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/4 "2024-09-20T15:15:08Z")

</div>

So the Dialogue Box adds the Topics to its own Grid Panel, got it. In this case this is a trivial and perfect job for the event dispatcher. And you can even use the one that comes with the button:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/2/07216f9585375dfbc5ed3ade4af7e1d7073052aa.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/7/a776406ccaae65cdf8e931d4eb963e5ebbb68d9d.png)

You can **instead** add a custom `Event Dispatcher` that sends specific data back:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/e/40ecb493480e8c398bab77e8c39f299bb0171eae.png)

* * *

Also, instead of this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/f/74f0ead813da4f0ad9470639d9233bf1e4ae0526.png)

You can create an exposed variable in the Dialogue Topic widget:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/0/0201a6549a4e83fdf50c349c25ffbcac0a7dd1af.png)

And pipe the data in:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/3/933285ab1d80763a91deb279be55459ba9d149cc.png)

Much neater and does not clutter the parent’s graph with stuff it does not need to know about.

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 3:21pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/5 "2024-09-20T15:21:31Z")

</div>

I already have it set up so that the dialogue topic widgets are getting created and everything. I just need to set it up so that once _they_ are clicked, the text in the dialogue box changes.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/5/47576dfc5eda07dbdcac95a6b56cac057007ea67.jpeg)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 3:22pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/6 "2024-09-20T15:22:06Z")

</div>

> [@davi1521](#):
>
> I just need to set it up so that once _they_ are clicked, the text in the dialogue box changes.

That’s what my solution does, **precisely**. You’d set the `Dialogue Box` text here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/1/c71607a75a0c4a9730e9f41bf6dd4cedce960971.png)

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 3:23pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/7 "2024-09-20T15:23:08Z")

</div>

okay. I don’t understand event dispatchers yet, so I saw it getting added to the logic that already works and I thought you were trying to do something else

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 3:25pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/8 "2024-09-20T15:25:20Z")

</div>

- add a dispatcher to the child widget
- when parent creates children, bind delegates so the children can talk to the parent
- when something happens in the child, the parent gets a notification

This is the most standard and natural way of doing it. Once you wrap your mind around dispatchers, there’s no looking back. Give it a try; it’s simpler than you think. Plug this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/d/8/8d8261842d3dd4d8e57713226c4bf9a7b27d5a80.png)

Into the `ED_SendTopic` custom event.

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 3:34pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/9 "2024-09-20T15:34:02Z")

</div>

like so?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/2/822664836efcd65df44a14aecc9b2837378f6baa.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 3:46pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/10 "2024-09-20T15:46:19Z")

</div>

No. Have a look at my second example where I create a custom dispatcher that sends text:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/e/40ecb493480e8c398bab77e8c39f299bb0171eae.png)

This needs to go, this is not a job for the Interface; the dispatcher delegate goes here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/d/dbd1bd6ea19b6506698e9825829cb10bff4e8369.png)

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 3:54pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/11 "2024-09-20T15:54:02Z")

</div>

But the W\_DialogueTopic widget where the button is doesn’t have any text to send. We get the dialogue from the table; I just need the text that goes into W\_DialogueTopic’s DialogueText variable because it’s the row name that I use to look up the text that does go into the dialogue box.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 4:00pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/12 "2024-09-20T16:00:22Z")

</div>

Yes it does, you send the text to the widget:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/e/71e0c201f01aba18fa25a9bd3e981cc8f4c92aee.png)

That’s why I suggested this setup which makes it highly efficient:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/0/0201a6549a4e83fdf50c349c25ffbcac0a7dd1af.png)

Because what you’re doing atm:

> I already have it set up

Is not really done correctly and would force you to read the data off the widget Text Block. You do not want to access the DT again, you’ve already done it once, the widget already has the text. If you **must** do it your way (hey, it’s your product):

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/1/9/519c83ee3589d16e97583d76960c04ab1560826f.png)

Suboptimal but should work. The idea is to never query widget fields for data, it’s not their job to provide it and it may lead to issues - mostly acquiring _stale_ data.

You want the widget to show some text - give it a variable and let it handle it internally, avoid having something else modify widget fields from the outside. It all subscribes to the getter / setter ideology which is one of the core foundations of the OOP.

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 4:17pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/13 "2024-09-20T16:17:15Z")

</div>

The only text in it is the dialogue topic, which shows up in the grid panel on the left of the dialogue box.

When I click on a W\_DialogueTopic widget, it should change the text that appears in the larger box on the right. I don’t want the text that is in W\_DialogueTopic to show up in the right; that would be redundant.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/e/f1e534693ea271c9759480366547127de3ad6d2b.jpeg)

I want to _use_ that text to look up a row name in my table, then return the text in that row.

What I have here is working now (mostly):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/a/2/3a254d96955e550382c85c89734be2680f05c4fa.png)

The only issue now is that, for some reason, clicking Hello and looking up the table row “Hello” passes the same value as the text in the table row “Sphere.”

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/1/a21489589c04d37535187997491bcd31d2db0a7d.jpeg)

I did a print string and you can see what is getting passed through the Event Dispatcher is correct:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/d/a1d55133b5fc8d01b59b7d70ce52c2e920a5023d.png)

Table looks fine as well

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/5/0/05052e3f70275d53b1b91806634e074148407e49.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 4:18pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/14 "2024-09-20T16:18:28Z")

</div>

You **insist** on doing the wrong thing for some reason:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/a/73a52f9372cde6a56f6611b8aa16bd55b6d43627.png)

You already have the text in the widget, there’s no need to access the Data Table again.

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 4:19pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/15 "2024-09-20T16:19:43Z")

</div>

The DialogueText variable is the text in the large box on the right side of the dialogue box widget. If I just pass the text from W\_DialogueTopic, then it’s just going to repeat the text from the left into the right!

I’ll show you…

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 4:21pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/17 "2024-09-20T16:21:27Z")

</div>

Doing it your way…

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/d/0ed43e7a700d8052c09614028aee0801411e5f45.png)

Results in this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/2/0d2783fc1b99ddd98e67c40fe4d01f18340f1852.jpeg)

This is not what I want.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 4:22pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/18 "2024-09-20T16:22:07Z")

</div>

Pass the entire DT struct to the widget you’re creating, the dispatcher can send it back. Or send back just this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/e/7/be7b3d48324ad62500046343ed9a994c707ea6ac.png)

Give the widget the text you want it to return via Dispatcher:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/d/07d05764ba286f5f67c362c1cfca9fa2fad00812.png)

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 4:25pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/19 "2024-09-20T16:25:42Z")

</div>

I see the issue now.

I need to somehow turn a text variable into a name.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/0/090722e13f48bf22cde00e291b0113d2bf0c09dd.png)

Or I just go back to the struct and change the variable type from Text to Name. That should work

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 20, 2024, 4:28pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/20 "2024-09-20T16:28:07Z")

</div>

> [@davi1521](#):
>
> I need to somehow turn a text variable into a name.

You can, sure. But why? Just give the widget all the data you want it to have. And return it.

* * *

If you really insist on searching the DT every time:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/b/c0b81771f64f7280411d55f0c095aaaae0933884.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/2/2/1224b7d514cccbbb0e0c4e5f69f1d2276aaa2098.png)

---

<div class="post-metadata">

**Author:** ![davi1521](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@davi1521](https://forums.unrealengine.com/u/davi1521)\
**Post date:** [September 20, 2024, 4:40pm UTC](https://forums.unrealengine.com/t/trying-to-get-a-variable-from-one-widget-to-another/2029851/21 "2024-09-20T16:40:12Z")

</div>

I still think you don’t understand what I’m trying to do. The W\_DialogueTopic widgets are the text on the left side of the dialogue box, they get created and named based on the row names in the NPC’s dialogue table.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/4/c/24c2569d692c67939b9c7823cf57bf815c1adf79.png)

The only thing inside of a W\_DialogueTopic widget is a button and the text (in this case, “Hello” or “Sphere.”)

The text that should appear in the right side of the dialogue box is inside of that table we referred to earlier. This is a Text widget inside of W\_DialogueTable, i.e,. the data table and the Text block that I want to change now, based on what I click on the left, are both already inside of W\_DialogueTable, not W\_DialogueTopic.

I only needed to get the text from W\_DialogueTopic back out to use as a lookup for the table. I’d rather do that than pass the table into W\_DialogueTopic, do the lookup, then pass it back into W\_DialogueTable.

Apparently, you can turn text into strings and strings into names.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/e/9eeca48c51eebc8c3e32dff61f2d17189860df18.png)

Edit: Unless you were suggesting that I go back and set it up so that, upon creating the W\_DialogueTopic widget, I also simultaneously look up the corresponding dialogue text and pack them both into the W\_DialogueTopic widget, then just get that when I call the event dispatcher?

I don’t much about programming best practices yet, but it seems like it would be more costly to replicate data that already lives in the object where I need it than to just look it up in the table each time a topic gets clicked.
