# How do I create a custom variable in a widget whose value can be bound to a function, like default widget values?

**URL:** <https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175>\
**Category:** C++\
**Tags:** binding, unreal-engine, CPP, question, UMG\
**Created:** [January 23, 2023, 10:05am UTC](https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175 "2023-01-23T10:05:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [January 23, 2023, 10:05am UTC](https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175/1 "2023-01-23T10:05:06Z")

</div>

I mean this type of binding that you can find, for instance, in a progress bar:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/9/9697d65f0a97307b00ed6d2fce6c05f688ad2aa9.png)

I found that to create this Bind menu I need to declare a respective delegate, like if my variable is `float Percent;` I declare `FGetFloat PercentDelegate;` and the Bind option will appear.

But how do I further retrieve the value from the bound function and set it to my custom variable?

Thank you!

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [January 23, 2023, 11:10am UTC](https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175/2 "2023-01-23T11:10:41Z")

</div>

So I’ve found one way to do that.  
I call `SetPercent(PercentDelegate.Execute());` under `NativeTick()`.  
I get that any such binding works on tick anyway, and this option should be the same performance-wise; however, I wonder is there’s another way to use this delegate without calling `Execute()` on tick.

---

<div class="post-metadata">

**Author:** ![lordlolek](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lordlolek/32/906205_2.png) [@lordlolek](https://forums.unrealengine.com/u/lordlolek)\
**Post date:** [January 23, 2023, 12:23pm UTC](https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175/3 "2023-01-23T12:23:18Z")

</div>

Not sure what you are trying to achieve, but usually if I need some variables to impact widget in editor, I use them in preconstruct event, which works similar to Construction script in BP.  
ie let’s say I want to lerp the tint of the progress bar with Percent as the alpha - if you change the tint in Preconstruct event you will see the tint changing when changing Percent value.

But again, not sure if that’s what you are looking for?

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [January 23, 2023, 12:31pm UTC](https://forums.unrealengine.com/t/how-do-i-create-a-custom-variable-in-a-widget-whose-value-can-be-bound-to-a-function-like-default-widget-values/755175/4 "2023-01-23T12:31:39Z")

</div>

Let’s say I have a weapon that has a condition, which goes from 0 to 1.  
The condition value may decrease depending on weapon usage, and there’s a progress bar that shows this condition at all times.  
The default progress bar (as well as a lot of default widget components) allows this binding: it means that it will monitor a certain value (through a bound function), and show in on the progress bar.  
I want to know the correct way to create these bindings for my custom variables, because I’m not using the default progress bar, but a custom widget I’ve created instead.
