Setting a Delegate for a UWidget in C++

Hello Community,

I am currently trying to implement a Function as the Delegate for my UProgressBar in C++. I have created the following:

in the .h
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (BindWidget), Category = “HUD”)
class UProgressBar* m_Healthbar;

in the .cpp
i am attempting to set the m_HealthBar.PercentDelgate to a function in the same class which is defined and set to a UFUNCTION();

The PercentDelgate says it is of the type FGetFloat but when i check the docs for this its not very helpful.
If anyone is informed or knowledgeable regarding this issue any help would be much appreciated.

Thanks.
Miike.

I haven’t used it before, but I was curious so I did some looking around. ProgressBar.cpp and other widgets that use FGetFloat have binding statements like this where the underlying widget’s delegate is set.


void UProgressBar::SynchronizeProperties()
{
        ...

	TAttribute< TOptional<float> > PercentBinding = OPTIONAL_BINDING_CONVERT(float, Percent, TOptional<float>, ConvertFloatToOptionalFloat);

        ...
	
	MyProgressBar->SetPercent(bIsMarquee ? TOptional<float>() : PercentBinding);

        ...
}

(TAttribute is mentioned here.)

Maybe that’s how things are meant to be done?

As far as using PercentDelegate itself (Or ValueDelegate from SpinBox and Slider, which also uses FGetFloat), I couldn’t find anything. Couldn’t find a definition for FGetFloat either, but I don’t have access to an IDE right now. I would think that, being a delegate, it should take a TAttribute like the underlying widget does.

Sorry, not the most useful answer. Just some stuff I’ve found.

Thanks for the Info Archduke_. Thats interesting. Its tough to find documentation or help on the deeper end of the Engine lol. Im going to continue fiddling around with this and see what i can come up with. The TAttribute<> is totally new to me.
Also regarding the FGetFloat, even in engine you cant search for a definition of it so im not sure where else to look. Maybe its too deep for intellisense/Visual Assist to find.

Thanks again.
Miike.

It’s just a function with no parameters returning float. If you make such a UFUNCTION (mark it BlueprintPure, and probably should make it a const function too), then you should actually be able to bind this from the dropdown within the UMG designer.

I guess you can setup the binding from C++, but you’d have to make sure you did so before SynchronizeProperties is called by the framework. I think it’s dangerous though, because UMG stores bindings that are set from the designer inside the widget blueprint class, so you’d be fighting against that by setting it directly.

Yeah i ended up just doing it in the Widget Blueprint. Thanks for the info Kamrann

Does PercentDelegate have any use when I only want to use C++? For updating UProgressBar I’m using a timer which calls UProgressBar::SetPercent() in a certain interval.

It’s not a case of C++ vs BP - whichever you’re using, you have the choice between pushing updates (like you’re doing) and having the widget pull the value (using bindings like PercentDelegate).

In many cases performance won’t be a real issue, but generally your approach is better because you push values only when they change, or at the rate you decide is necessary. Bindings by default are updated every tick, which is often overkill.