# Set text values with public variables

**URL:** <https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469>\
**Category:** UI\
**Tags:** variables, unreal-engine, instances, Widget, Blueprint, question, UMG\
**Created:** [July 21, 2021, 3:59pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469 "2021-07-21T15:59:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebeccaSimpson87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RebeccaSimpson87](https://forums.unrealengine.com/u/RebeccaSimpson87)\
**Post date:** [July 21, 2021, 3:59pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/1 "2021-07-21T15:59:44Z")

</div>

I’m attempting to make a map players can move around, with pins they can click on to show the information of npcs that live at that location. I’m fairly new to blueprint scripting, so there may be a better approach. This is just what I have pieced together with various tutorials.

I have created a blueprint with several public variables that I use to set the values of a struct table. That table is used to set the text value of a widget by casting to this blueprint to fetch the value of the variables.

 ![344619-help4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/0/9/1092675558bbfb34f53ac72085a44235fec59193.png)

 ![344620-help5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/7/5/5755f16f24323877c495dd556eea02ba0ca356ec.png)

The idea is that I would be able to have multiples of these pins on the in the viewport and set the text of each individual, while reusing the same blueprint, so that I don’t have to create a new blueprint for each npc. To some extent, this works, and I can set the text through the editor/outliner, but the issue is that it sets the same text for every instance of this blueprint. Generally, the editor uses the text from whatever instance I set most recently to populate all of them.

 ![344651-help1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/7/b/77b027b65712f139da54aa58db9c0983f3cd4e6a.png)

![344652-help2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/e/8/3e8b741710facb1733312dbccf2014ce77919d35.png)

![344653-help3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/4/144c33adf3f2a0914b8b0771347b30f2ad221831.png)

Is there a better way to approach this, or something I’m missing so that each instance of the blueprint uses it’s own information?

---

<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:** [July 21, 2021, 4:40pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/2 "2021-07-21T16:40:08Z")

</div>

- functions bound to text blocks (2nd pic) execute every frame, if you mouse over the Get All node, it will tell you not to use it every frame as it’s a slow operation
- Get All does not guarantee element order, you actually do not know which element you’re getting
- even if you knew which index is which actor, you’re Getting element 0, getting text of _that_ actor and setting it to _all_ actors text. All actors end up with text from actor 0 (and we don’t even know which is 0 - this will seem random)

---

<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:** [July 21, 2021, 4:41pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/3 "2021-07-21T16:41:18Z")

</div>

Just to clarify, it’s like this right:

- actor
- widget component

Each actor has a bunch of variables that you set and you need each actor’s widget to show them. Could you confirm?

---

<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:** [July 21, 2021, 5:04pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/4 "2021-07-21T17:04:46Z")

</div>

Here’s something that I tried to fit into the existing bits you’ve learnt.

- inside the widget with the text blocks, create the same struct variable you have in the pin actor - so you can poll that struct’s values and feed them directly into the fields:

![344661-struct.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/0/5/3059b7637289c532b81dd6d0087c0f9b02d1847d.png)

- in the actor with the widget component:

 ![344662-updatestruct.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/8/7884e2bb2dfe9525cb85e851996999acd6ddad26.png)

* * *

Do note, you do not really need to make several text variables and assemble them into a struct, instead you can flag the struct variable itself as `Instance Editable` and then:

 ![344663-tip.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/b/afb07c9d9cfe83b471bf05fb31d331bb3a74436e.png)

---

<div class="post-metadata">

**Author:** ![RebeccaSimpson87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RebeccaSimpson87](https://forums.unrealengine.com/u/RebeccaSimpson87)\
**Post date:** [July 22, 2021, 3:15pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/5 "2021-07-22T15:15:24Z")

</div>

Thank you! This worked for me! The only issue I ran into was your comment about being able to make the struct instance editable. With public variables fed into the struct, I could set the text of each instance, but if I just tried to set it through the public struct, it didn’t work. The text showed as blank.

---

<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:** [July 22, 2021, 3:29pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/6 "2021-07-22T15:29:31Z")

</div>

> The text showed as blank.

Hard to tell what’s up without seeing more but perhaps the variables you previously set up override the data in the struct? Were you to go with the Instance Editable struct:

 ![344693-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/4/b4489d1adf961a103531ba46555a7e5b17fe0b8d.png)

---

<div class="post-metadata">

**Author:** ![RebeccaSimpson87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RebeccaSimpson87](https://forums.unrealengine.com/u/RebeccaSimpson87)\
**Post date:** [July 22, 2021, 3:40pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/7 "2021-07-22T15:40:00Z")

</div>

Looks like that was the case with the variables overriding. I got rid of them and it’s working just fine now!

Just a follow up, this may be a more involved, but is there any way to bind the text in the widget to a text array element, rather than a single text variable? I don’t see the array come up in the binding drop down. If not, that’s fine, I was just hoping it was an option for organization’s sake. Thanks again for the help, I really appreciate it.

 ![344674-array.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/1/e3144623fac10379f46213ff6f1c59f431eae086.png)

![344675-binding.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/a/6/da646e668051aca10b4c7840283bfc8687528d0e.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:** [July 22, 2021, 4:04pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/8 "2021-07-22T16:04:52Z")

</div>

That is currently not possible in BPs. One easy workaround is this:

![344694-screenshot-6.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/8/6/a861e387cd88ceb158603e821eb969c3acaf65f7.png)

 ![344695-screenshot-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/0/b403e9fef5951f784abed455e5ae2bba8e789d66.png)

You’d need to punch in index manually for every field but this can be automated further. Irrelevant if you have 5 fields, and pretty much a must if you have 500 fields…

* * *

Alternatively, you could expose Text Blocks as variables:

![344696-screenshot-7.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/2/c/52ccd233012ab71ce5c3e2aaf375315d797e1f95.png)

- inside the widget:

 ![344697-screenshot-9.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/a/36a6863252939e2d3eb2e9d47c2b87e77de62445.png)

- and instead of setting the struct value, call a custom event which will do both - set the struct value and push text into fields

 ![344698-screenshot-8.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/5/cc5596b9071203fef8641e71f5c3016aae3df37d.png)

Or perhaps the struct inside the widget is not even needed, the Custom Event may be enough to set everything up. Although having a struct may help with other things.

* * *

This is especially useful when you know the data will not change often or not update at all. Binding something to a widget field executes _every frame_ whereas the above would execute _once_. If you have 10 Pin actors, it does not matter. If you have 1000 pins, it does.

---

<div class="post-metadata">

**Author:** ![RebeccaSimpson87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RebeccaSimpson87](https://forums.unrealengine.com/u/RebeccaSimpson87)\
**Post date:** [July 22, 2021, 4:10pm UTC](https://forums.unrealengine.com/t/set-text-values-with-public-variables/486469/9 "2021-07-22T16:10:16Z")

</div>

Oh, this makes sense! I should have caught that now that I know how to set the struct values from the blueprint. Thank you!
