Parent & child healh bar widget BP linked to enemy parent & child

I have an enemy parent class with a widget bp class. Creating multiple children of the enemy does not allow the widget to work because i have to cast to parent health bar widget in parent enemy. The child enemys are still casting to the parent health bar. I tried creating children of the widget class and setting it in class defaults. Ive tried many work arounds. The main thing im trying to accomplish is different health values for different children, along with other attributes.

Other than manually creating a seperate widget for each child enemy and adding the logic for health and health bar, i cant think of any way to get around this. I have watched too many tutorials and been through so many google searches. Cant find any help on this. There has to be a way to do this. Any help is greatly appreciated!

hi @TLOA

I am a little confused as to why you need to cast to the parent class?

So in my head what you want should work like this:

  1. parent blueprint for your enemies
  2. child blueprints made for each type of enemy with their unique meshes etc
  3. create a health bar widget
  4. place the health bar widget inside the parent blueprint

All the children should then be able to access their OWN health bar as the widget is a component of the parent, the child will also inherit their own.

am i missing the point? if not i hope this helps!

If you are unsre how to place a widget inside your blueprint check this out

How To Create Enemy Health Bars in Unreal Engine 5 - YouTube

1 Like

No i think you get it. What you describe is exactly what i want to do. The tutorial you posted is actually exactly the tutorial i used to create the widget.

There are 2 issues. The first problem is that the children do inherit the health bar (it is visibly there), but only the parent health bar updates. The child health bars do not update at all, however their health system does work because i can kill them when i hit them enough.

The second problem is that i want the children to have different max health from the parent. I do this by adding a BP structure with a health float variable that can be edited in the class defaults of each child. Again here, this works on the enemy, because if i change the health value from like 100 to 10, they die faster as expected, but the widget stays full.

I attempted to fix this by making children of the widget. The effect is still the same. I just feel like it should work and i have no idea what im missing here. Either way i appreciate your reply and any further guidance you could offer.

One more quick note. In the parent enemy, i have to cast to the healthbar widget to update it. Thats the only place where a cast occurs. I know i said it weird.

in the parent all the code passes down to the children, so you would cast your widget component to the healthbar widget type. then set it direct

The children will auto do the same

Yea it does. I just cant make it so that i could set a childs health the be different without having half-full or over filled healthbars. I made a work around by setting a variable in the parent class struct that modifies the health variable for the parent, whick i can manipulate in the children. Its not what i was hoping for but it works. Thank you for trying to help!!