How to bind Health Bar Widget to an enemy

Hi, I’m trying to connect a Widget (which is shown above an enemy) that indicates Health.
The point is, I can’t find an enemy reference node.
As an example I’ve connected “Get Player Character” so all Widgets (Player and Enemies) point to Player’s Health.
Is there a specific node to indicate “self” (intended as the Enemy) or what can I do? Thank you all.

1 Like

2 questions:

  • are you using a widget component?
  • do you need to update the enemy health bar every frame (usually 60 times per second)

Binding functions (what you have atm) is generally not such a great idea and much better, event driven, approaches really shine here.

Do tell.

Thank you for answering! Yes, I’m using a widget component and I need to update enemy health only when its health is affected. Any suggestions?

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 refence to the widget embedded in the component so the owning actor can access it easily
  • Event 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.

2 Likes

It works, thank you very much!