# Widget Healthbar binding to actor

**URL:** <https://forums.unrealengine.com/t/widget-healthbar-binding-to-actor/501986>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE4-27, Blueprint, question\
**Created:** [February 25, 2022, 5:04am UTC](https://forums.unrealengine.com/t/widget-healthbar-binding-to-actor/501986 "2022-02-25T05:04:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 25, 2022, 9:59am UTC](https://forums.unrealengine.com/t/widget-healthbar-binding-to-actor/501986/2 "2022-02-25T09:59:24Z")

</div>

> [@Cyrus\_80](#):
>
> it was advised to use blueprints when binding a actors health with the actors healthbar.

Bound functions execute every frame, this variable would be polled every frame. Not a biggie if it’s just a bunch of entities, but if _everyone_ is doing it all the time, it may become a performance factor; besides, not a good practice to start with - why waste cycles. Blueprints are sluggish enough. Consider adopting an Event Driven approach instead, whenever you can.

* * *

Regarding why what you tired does not work:

- the `New Health` variable is not updated when you take damage. It’s updated only once - when the widget is constructed, added to the screen. No further updates are done.
- the `Get All Actors of Class` node has no class selected in the dropdown. It also does what is says on the tin - it gets _ALL_ instance of this class, and we don’t even know the order so you don’t know which one `Get 0` fetches! Besides that, no point in getting ALL instances - we want to update only this one, the one belonging to the enemy getting hurt.

* * *

> Please help me out because at this point im just guessing.  
> Maybe some blueprints picture examples ,if that would be possible would be great

## The Widget

- create a widget with just a progress bar, no canvas; no script goes in here:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/6/486af08343dc113073c3704ed0200c0e70a2c46d.png)

- ensure it’s filled to the brim with good health; even though the progress bar reads `Percent`, it is actually a 0-1 range:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/b/74b64389ad109c62a8206b26ab5172700c25b82f.png)

* * *

## The Enemy

- make a new actor class with a couple of variables representing health, ensure their default values make sense - here it’s 100/100. You can do this in C++ or BPs:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/c/9fcdba7bb78755035c21493753229a6d4e3b3c41.jpeg)

- I added a `Static Mesh` component to the actor so we can see it represented with this purple pyramid in the world
- add a `Widget Component` - it will hold onto, display and maintain the lifecycle of the progress bar widget we created earlier
- ensure you’re happy with the `Draw Size` and Z offset - so the bar appear above the actor’s mesh (you can also use Screen Space instead of World Space)

* * *

## Updating the widget

- when the game begins The Enemy actor queries its own widget component and creates a direct reference to the widget the component instantiated - at this point it’s more convenient than casting every time we want to access it:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/1/b/11bbb8f625ca17c931ad5e6305c91ab19181bd24.png)

- above, when this actor is dealt damage (via a snazzy built-in system), we calculate the damage done and update the progress bar using the abovementioned reference
- here it is set up in such a way that we can’t receive damage more often than twice a second

* * *

## Dealing Damage

- when other world entities interact with The Enemy actor, they now can…

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/4/0d47b38785e01a356cd8fac3efaefdcb713c00e9.png)

…resulting in:

* * *

The above can be set up in many ways but I did not want to involve Event Dispatchers here.  
Hope it makes sense.

---

_[View the full topic](https://forums.unrealengine.com/t/widget-healthbar-binding-to-actor/501986)._
