How do I bind a widget property to something?

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

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][1]

1 Like

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

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

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 :slight_smile:

	PROPERTY_BINDING_IMPLEMENTATION(bool, bIsEnabled);

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?