# How do I bind a widget property to something?

**URL:** <https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140>\
**Category:** UI\
**Tags:** property, unreal-engine, Widget, CPP, question\
**Created:** [May 30, 2021, 9:38am UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140 "2021-05-30T09:38:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anti\_Monitor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anti\_Monitor](https://forums.unrealengine.com/u/Anti_Monitor)\
**Post date:** [May 30, 2021, 9:38am UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140/1 "2021-05-30T09:38:34Z")

</div>

I want to bind property IsEnabled of the button to the text of EditableTextBox.

I need the button to be enabled if the text is written and disabled if the text is empty.

I want to understand how to do in C ++ what is shown in the picture.

![340227-снимок.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/7/2/87299aa4fdfdfe76537aeb1ce53b22ca9e76c78e.png)

---

<div class="post-metadata">

**Author:** ![Mahoukyou](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mahoukyou](https://forums.unrealengine.com/u/Mahoukyou)\
**Post date:** [May 31, 2021, 3:54pm UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140/2 "2021-05-31T15:54:03Z")

</div>

I wouldn’t really use these bindings inside widgets. They are called every frame (when widget is visible) and 99.99% of the time, you don’t need something to be called every frame. In such a simple example it doesn’t matter, but once you build your game more and more, the 0.001ms per tick will add up.

But to answer your question, simply create a binding function and inside that function check inside if your textbox is empty.

Better way would be to create a binding when text changes and update if the button is enabled based on that, this way, the execution is done only when player uses input.

Here is a quick setup of both: [[2021 05 31 17 44 37 - YouTube](https://youtube.com/video/5kTTQTUVnV8)][1]

 ![340285-scr1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/2/a220763d76f37ef894817882589e75d35e2aa5d6.png)

---

<div class="post-metadata">

**Author:** ![Anti\_Monitor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anti\_Monitor](https://forums.unrealengine.com/u/Anti_Monitor)\
**Post date:** [May 31, 2021, 8:01pm UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140/3 "2021-05-31T20:01:02Z")

</div>

Thank you!  
I was hoping there was an event system for bindings.  
You answered about blueprint widget, but I wanted to know about C++ widget (UUserWidget). But I think it works the same

---

<div class="post-metadata">

**Author:** ![Mahoukyou](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mahoukyou](https://forums.unrealengine.com/u/Mahoukyou)\
**Post date:** [May 31, 2021, 8:33pm UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140/4 "2021-05-31T20:33:31Z")

</div>

Ah, my bad. So in C++, for the first example (action on value change) you would do exactly the same thing, you would bind (normally) ufunction to a specific event on an object, in this case “OnTextChanged”. Something like this (just mockup):

```
    void SomeInit(...)
    {
    	UEditableTextBox* const myTextBox; // somewhere else declared/initialized, e.g. in blueprint
    	if (myTextBox)
    	{
    		myTextBox->OnTextChanged.AddUniqueDynamic(this, &ADungeonGameCharacter::TextChanged);
    	}
    }
    
    void ADungeonGameCharacter::TextChanged(const FText& text)
    {
    	// enable/disable button based on if text is empty
    }

```

More information on delegates can be found here: [Delegates | Unreal Engine Documentation](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Delegates/)

For the normal binding that is on your screenshot, I doubt that this is easily doable, since the binding is usually is in a private scope. If you want, you can take a look at TAttribute::Bind(), TAttribute::Get() in Attribute.h, as well as on the blueprint binding for IsEnabled in Widget.h. But I’d just stick to the previous example 🙂

```
	PROPERTY_BINDING_IMPLEMENTATION(bool, bIsEnabled);
```

---

<div class="post-metadata">

**Author:** ![ilbiffi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ilbiffi](https://forums.unrealengine.com/u/ilbiffi)\
**Post date:** [June 8, 2022, 3:44pm UTC](https://forums.unrealengine.com/t/how-do-i-bind-a-widget-property-to-something/484140/5 "2022-06-08T15:44:41Z")

</div>

Sorry to resurrect the thread. Is the binding called every frame also if it refers local variables in the widget itself? or only if it refers a function?
