Enemy Bar

Hi,

How to reach this point ?

  1. I create new widget bp to display enemy life. Problem appear when I have to pin some object anybody know what should be there ?


    Maybe you have better ideas how to display enemy HP bar.

  2. How to remove this widget when anemy is died (I try “remove all widget” but this remove also my widget)

I will be gald if enybody could help me

  • create and expose the enemy reference variable in the widget
  • have a Health Point text variable in the enemy (do any calculations there, rather than in the widget)
  • create the widget in the enemy blueprint:

You can then directly bind the Health Points text variable with no need to even use functions or perform expensive casts every frame:

Before this enemy dies, use the wHP_BarReference Variable in pic 1 to remove it from the Viewport.

Thank you for the tips on setting the life of the opponents, but I do not know why I still have problems with removing the widget when the enemy character dies, everything is done correctly but the widget still remains.

Can you please use the reference you setted and not the return value directly, also IsValid node can be a nice implementation for prevent errors deleting one thing that doesn’t exist yet or already exist.

And If you’re creating/destroying the widget inside the enemy actor blueprint you need to remove from viewport before you destroy the enemy or that reference will be always empty, if you destroy the enemy and then remove the health bar the reference of the widget will not exist anymore because the enemy actor doesn’t exist;

so first RemoveHpBar -> Destroy Actor

This whole post. Especially that I saw information regarding the create widget nodes not holding onto the reference for too long as of 4.19 or 4.20.

I have solved the problem though but I do not know if it’s the right way. Before widget I try remove from AI character when HP is 0 or lower but without effect.
Now in widget enemy I set event tick check if enemy character has any health point, if not widget is destroyed and this is working fine.

this is not the best method in my opinion, you must check on event Any Damage if the health value is 0, not on a timer tick.