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.
Hey, not sure if it’s still relevant but i’m using next code
/** 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.