Use one Health Bar for several Enemies
I want to use ONE healthbar for several enemies. For that i created a widget component in the enemy_BP and created a Healthbar-Widget with binding the Progress Bar. But it only works for the first enemy and it reduce the healthbar of the other enemy at the same time. If the first enemy is dead the other enemy has a full healthbar and reduce progressbar by hitting him. What i am doing wrong? Is "GetAllActorofClass" the wrong way? I tried to cast in the GetPercent-Function to my Enemy_BP but dont know what to connect to the "Object-Pin".
asked Jan 28 '19 at 05:06 PM in Blueprint Scripting
Hey buddy, just did this myself too.
The problem in your picture is that you're using get all actors of class. Which means all actors in that class will update the health value. Lemme show what I got.
So these are some sample enemies with healthbars:
As you can see it tracks individual health. I assume this is what you're looking for?
This is the function for setting the health bar level:
So simple it's almost stupid isn't it?
Here's how it gets sets when enemy is initalized:
It's set to hidden in game until the enemy has a target because it's set to rotate with the screen and unfortunately cannot be prevented from showing through walls (you don't need this in the blueprint, just tick the box for the component). There are workarounds for this but they are time-consuming and I'm lazy. I just do show/hide instead.
EnemyHP is of course my widget blueprint. HP widget ref is a variable I made (drag out as enemy hp --> promote to variable). And healthbar is the actual widget component attached to the enemy in the viewport.
I was gonna add how it's updated when it takes damage but it's kinda pointless since it's the exact same (just the health variable is different).
If you have any questions be sure to fire away. The "Max health" variable is totally optional, you can divide by whatever you like to get it as a percentage (health points need to be between 0 and 1 in my version, but you can make it between any values you want in the widget blueprints).
The benefit of this is that it can literally be used for any enemy you have. If it's a big enemy just scale it up and move it higher in the viewport for example, or you can set it to its feet. Or you can make the widget stick to your own screen if it's a boss type where you want visible health on screen instead of over the enemy (I'd probably duplicate it and make some visual alterations just for looks in that case). For that kind of thing you'd use add to viewport instead though.
Yes, you just make a widget, add a progress bar with a function that updates based on the input float value. Then in your enemy BP add a widget component, select the health bar widget (or whatever you called the widget with the progress bar), now you have a widget for each enemy instance. In your enemy BP script the logic to update the widget based on current health. So when the event is damaged, have a function that gets called which grabs the widget component, cast it to the health widget and call the function within the health widget that will update the progress bar.
answered Jan 28 '19 at 07:11 PM
Nebula Games Inc
Follow this question
Once you sign in you will be able to subscribe for any updates here