UMG & C++, AddBinding on ProgressBar

Hi guys,
I’ve declared my Progress Bar like this in my HealthbarWidget.h file:

	UPROPERTY(meta = (BindWidget))
	UProgressBar* HealthProgressBar;	

This works well, but how do I bind a value to the Percentage of the Progress bar?
This is the current state of my HealthbarWidget.cpp file:

void UHealthBarBaseWidget::NativeConstruct()
{
	Super::NativeConstruct();
	
	//Bind this to GetHealthBarPercentage() function!
	//HealthProgressBar->AddBinding();
}

float UHealthBarBaseWidget::GetHealthbarPercentage()
{
	return 50.f;
}

I guess this works with delegates, but I don’t understand them fully and I cannot seem to get the syntax right.
I guess I understand the basic concept but I could really use some help here.

Thanks for your time and help!

I’m achieving this now via the UWidget::NativeTick() Function. Updating the SetPercentage() value. The question still stands though.

Hey, not sure if it’s still relevant but i’m using next code :slight_smile:

        /**  Assgin bind funtion to the health bar */
    	UProgressBar* HealthBarWidget = (UProgressBar*)GetWidgetFromName(TEXT("HealthIndicator"));
    	if (HealthBarWidget != nullptr)
    	{
    		HealthBarWidget->PercentDelegate.BindUFunction(this, "GetHealthPercentage");
    		HealthBarWidget->SynchronizeProperties();
    	}

Hi! Your mistake is return 50.f;
percentage is a value from 0.f to 1.f
for instance your health is 30.f and max health is 100.f
percentage is 30.f / 100.f = 0.3f
Tick is nice place to do that kind of stuff.

also check for divide by zero. max health anyway can not be 0.f