# How to bind a UTextBlock

**URL:** <https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220>\
**Category:** UI\
**Tags:** binding, unreal-engine, Widget, CPP, question\
**Created:** [October 4, 2015, 11:50am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220 "2015-10-04T11:50:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_094df259](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_094df259](https://forums.unrealengine.com/u/anonymous_user_094df259)\
**Post date:** [October 4, 2015, 11:50am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/1 "2015-10-04T11:50:43Z")

</div>

Hi,  
I’d like to bind a UTextBlock to some UObject member but I’m not sure how exactly to do it.  
At the moment I have this:

```
UTextBlock *label = NewObject<UTextBlock>(outer, UTextBlock::StaticClass());
label->SetText(text);

```

which works fine but I want to change the text dynamically at runtime.  
I can see in the [UTextBlock doc](https://docs.unrealengine.com/latest/INT/API/Runtime/UMG/Components/UTextBlock/index.html) that there is a member “TextDelegate” but it’s not clear to me how exactly the code should look like.  
Can you guys give me an example please?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [October 4, 2015, 12:58pm UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/2 "2015-10-04T12:58:49Z")

</div>

Same as any other delegate, but because it’s not multicast delegate you need to use BindDynamic instead of AddDynamic

```
label->TextDelegate.BindDynamic(this,&USomeFancyClass::SomeFunction());

```

Argument where you got “this” is a object on which function will be called, and “this” means object which function you coding in belongs to.

Now, delegates can expect different functions, currently API reference very lacking on this info, so best way to figure out what function to use is by searching delegate type (in this case FGetText) in UE4 github and usally delegate decleration will be in one of results as delegates are usally declered at begining of source files, they look like this:

```
DECLARE_DELEGATE_RetVal(FText, FGetText);

```

[https://github.com/EpicGames/UnrealEngine/blob/311e18ff369078e192a83f27834b45bdb288168a/Engine/Source/Runtime/UMG/Public/Components/Widget.h#L102](https://github.com/EpicGames/UnrealEngine/blob/311e18ff369078e192a83f27834b45bdb288168a/Engine/Source/Runtime/UMG/Public/Components/Widget.h#L102)

In this case you need to make function without any arguments (not OneParam or somethign like that in name) and return FText value (has RetVal in name and FText in begining is type of return). If you have MULTICAST in name it means it’s multiucast delegate and it can bind more then 1 function and you use AddDynamic, if it missing like in this case it a single cast delegate and it can have only one function binded, if you bind again function will be replaced and you use BindDynamic insted. Obviously single-cast delegate is needed to set up return value delegate.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_094df259](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_094df259](https://forums.unrealengine.com/u/anonymous_user_094df259)\
**Post date:** [October 4, 2015, 3:40pm UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/3 "2015-10-04T15:40:54Z")

</div>

Thanks, this worked.  
Can you clarify why I should use BindDynamic() if this is not a dynamic delegate? Also what is the difference between dynamic and regular delegates?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [October 4, 2015, 4:23pm UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/4 "2015-10-04T16:23:25Z")

</div>

that they can be serialized, here you have docs about delegates:

> **[Delegates](https://docs.unrealengine.com/5.1/en-US/delegates-and-lamba-functions-in-unreal-engine/)**
>
> Data types that reference and execute member functions on C++ Objects

---

<div class="post-metadata">

**Author:** ![Repin\_Design](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/repin_design/32/598391_2.png) [@Repin\_Design](https://forums.unrealengine.com/u/Repin_Design)\
**Post date:** [December 18, 2017, 8:40am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/5 "2017-12-18T08:40:57Z")

</div>

i dont get how to get this done ;( and i cant find examples.

---

<div class="post-metadata">

**Author:** ![tjrdud02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tjrdud02](https://forums.unrealengine.com/u/tjrdud02)\
**Post date:** [February 20, 2018, 6:26am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/6 "2018-02-20T06:26:10Z")

</div>

TestTextBlock-\>TextDelegate.BindDynamic(~~) ;

Must Call After

TestTextBlock-\>SynchronizeProperties();

---

<div class="post-metadata">

**Author:** ![SAU-87](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SAU-87](https://forums.unrealengine.com/u/SAU-87)\
**Post date:** [September 14, 2020, 6:50am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/7 "2020-09-14T06:50:53Z")

</div>

I don’t know how it was before, but just in case I want to draw your attention to the fact that in version 4.25, brackets are not needed.  
label-\>TextDelegate.BindDynamic(this, &USomeFancyClass::SomeFunction);

---

<div class="post-metadata">

**Author:** ![FTPM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FTPM](https://forums.unrealengine.com/u/FTPM)\
**Post date:** [April 14, 2021, 4:38am UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/8 "2021-04-14T04:38:06Z")

</div>

I did it here and it worked:

1. I used the TextDelegate property from the UTextBlock class.
2. This property expect a FText as a return, so the function you bind must return this type and you have to make all conversions for that.
3. My example below:

**Initialization an pointer protection for the Text** :

```
/* 18 Pointer protection PowerBarPercentText */
	if (PowerBarPercentText)
	{
		PowerBarPercentText->SetText(FText::FromString(""));		
		PowerBarPercentText->TextDelegate.BindUFunction(this, "GetPowerBarPercentageString");
	}

```

**The function that was binded, returning the power percent as the content for the text**

```
FText UIceBreakerUserWidgetInGame::GetPowerBarPercentageString()
{
	if (MyClassThatHaveTheFuncion)
	{
          return FText::FromString(FString::SanitizeFloat(MyClassThatHaveTheFuncion->HitPowerPercent));
	}
	else
	{
		return FText::FromString("");
	}
}
```

---

<div class="post-metadata">

**Author:** ![dr.zy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dr.zy/32/611271_2.png) [@dr.zy](https://forums.unrealengine.com/u/dr.zy)\
**Post date:** [April 27, 2023, 3:14pm UTC](https://forums.unrealengine.com/t/how-to-bind-a-utextblock/334220/9 "2023-04-27T15:14:48Z")

</div>

thx a lot,it works.
