# Why can I not just reference the text field of a HUD?

**URL:** <https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721>\
**Category:** UI\
**Tags:** hud, text, unreal-engine, score, question\
**Created:** [July 28, 2021, 2:52pm UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721 "2021-07-28T14:52:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom8788](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom8788](https://forums.unrealengine.com/u/Tom8788)\
**Post date:** [July 28, 2021, 2:52pm UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/1 "2021-07-28T14:52:31Z")

</div>

The reason why people are asking over and over again how to display score or energy or any other text on screen, is because the logic is over-complicated. WHY can I not just reference a text field from a widget blueprint? I get a value from one object, and I set the text property of the text field of the widget. How difficult can that be?

Doing such a simple and very common thing gives me headaches every time. And it’s just as complicated in Unity, so developers seem to overlook this.

By the way, big fan of Unreal, just suggesting that you can really stick out when you simplify displaying text on screen.

---

<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 28, 2021, 5:05pm UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/2 "2021-07-28T17:05:34Z")

</div>

> WHY can I not just reference a text  
> field from a widget blueprint?

You can…

 ![345046-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/2/762902235fc731bd48caeba1b26f2ca995a9354c.png)

* * *

Or give the widget a reference to the player:

 ![345047-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/1/1615a1a603f8f4c19aa34183f4def029c2b215e1.png)

![345048-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/c/0/ec07ab77bdb7184c45b5e72af8dd5f0bcfb3247c.png)

* * *

_There are so many more methods…_

You choose the right tool for the job. It all depends on how / how often updates need to happen and who is responsible for the updates. It’s up to you how to organise it. There is no one best way; albeit Event Driven approach is desired in most cases.

---

<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 28, 2021, 5:13pm UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/3 "2021-07-28T17:13:44Z")

</div>

> just suggesting that you can really  
> stick out when you simplify displaying  
> text on screen.

If you have constructive criticism (or non-constructive! - both are more than fine, I guess), may I suggest you voice it here:

> **[Feedback & Requests](https://forums.unrealengine.com/c/general/feedback-requests/50)**
>
> Tell us how to improve our tools!

An Answer Hub post is likely to go under Epic’s radar.

---

<div class="post-metadata">

**Author:** ![Tom8788](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom8788](https://forums.unrealengine.com/u/Tom8788)\
**Post date:** [July 28, 2021, 9:08pm UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/4 "2021-07-28T21:08:37Z")

</div>

Will do, thanks for the hint!

---

<div class="post-metadata">

**Author:** ![Tom8788](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom8788](https://forums.unrealengine.com/u/Tom8788)\
**Post date:** [July 29, 2021, 9:21am UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/5 "2021-07-29T09:21:59Z")

</div>

@Everynone, thanks for your reply, but you’re oversimplifying what needs to be done. I compare it to let’s say Visual Basic in the stone age. I just create a text field or a label in my viewport, let’s name it txtScore. The only thing I need to do to get the text changed is txtScore.text = 1234.  
The way I see this in blueprint is create a reference to the text field: so create a variable of type HUD, put that HUD on the blueprint, drag a line from the blue pin, and choose “Set txtScore” or “Get txtScore”, nothing more or less. This method is valid for any scenario.

Why I need to create the widget once more in the level blueprint is something that is not intuitive in my opinion. I already created it on screen, didn’t I?

---

<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 29, 2021, 10:02am UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/6 "2021-07-29T10:02:01Z")

</div>

> I compare it to let’s say Visual Basic  
> in the stone age.

UE4 has moved past that; you’ll either conform and adapt or keep chipping at rocks.

> Why I need to create the widget once  
> more in the level blueprint

You do not. This is created in the character, as seen in the pic. One actor, one widget. You can even use a widget component that will create a widget for you automagically. So you just add a component to any entity in the world. And you can even extend an existing component class…

![345134-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/b/e/1be038c936eb8736e0431f280630b73403f36811.png)

> The only thing I need to do to get the  
> text changed is txtScore.text = 1234.

That’s precisely what my second example does - I am pointing a text field at a variable in the player.

```
textblock.text = player.health

```

It pulls data from the the player - this polling is done every frame. It’s 3 clicks away and probably the easiest way to use it. Also, widgets can pull data from structs. So if the player’s values change, the UI updates in real time.

> The way I see this in blueprint is  
> create a reference to the text field:  
> so create a variable of type HUD, put  
> that HUD on the blueprint, drag a line  
> from the blue pin, and choose “Set  
> txtScore” or “Get txtScore”, nothing  
> more or less. This method is valid for  
> any scenario.

And that’s precisely what my first example does. I’m setting a value in a text field of a widget.

But this approach is very limited in scope and scales poorly. I cannot recommend it unless we’re talking about just a handful of variables. One should _at least_ consider creating a Custom Event in the widget and feed it data - the widget then uses this data to populate its fields without exposing anything.

UE4 is very [OOP][2]. It’s pretty much a must to work this way these days.

---

<div class="post-metadata">

**Author:** ![Tom8788](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom8788](https://forums.unrealengine.com/u/Tom8788)\
**Post date:** [July 30, 2021, 9:15am UTC](https://forums.unrealengine.com/t/why-can-i-not-just-reference-the-text-field-of-a-hud/486721/7 "2021-07-30T09:15:41Z")

</div>

Thanks Everynone, much appreciated!
