As a general rule of thumb, the less you do in the widget, the better. Here, it’s the actor that drives the widget behaviour and feeds it data, rather than widget referencing the actor and trying to pull the data out of the actor.
Remove Binding
from the Progress Bar
and add this in the enemy blueprint:
From the top:
Begin Play
creates a reference to the widget embedded in the component so the owning actor can access it easilyEvent AnyDamage
fires when damage is applied to this actor- we deduct health
- current HP / Max HP is the percentage of hit points left and can be sent to the progress bar -
Set Percent
- when currentHP is zero or less, we Destroy Actor (optional ofc)
This way, this script runs only when the enemy receives damage rather than all the time. This may not mean much with a couple of enemies but all those Ticks quickly pile up.