Enemy 2D Health Bars

Hi,

I have been struggling with this for days now. I’m making a tower defense game and I want the player to be able to target 3D AI and then have a 2D UMG widget health bar show at the top of the screen which shows and hides when the crosshair goes over the enemy. I have managed to get the showing and hiding done perfectly, and when 1 AI spawns everything is perfect. When I spawn more than 1 AI the UMG widget gets replaced by the spawned AI’s HP and when I hover over the first AI the second AI’s health is displayed (I kind of understand why it’s doing this).

I need to be able to somehow only make sure that my widget health bar corresponds to the enemy which has been traced and doesn’t interfere with any other spawned AI. I’ll post my blueprints below. I’m quite surprised that many people haven’t wanted 2D health bars like this, either that or i’m missing something, will be greatly appreciated if someone can help me with this :slight_smile:

your EnemyHealthBarWidget has a local variable EnemyHP which might need to be updated right before the ShowWidget node, so it reflects the state of the new enemy.

try setting EnemyHP equal to the EHealth variable of the enemy, which you can get by casting from the HitActor reference from the LineTrace.

also, you should probably do those traces in your player controller, not in the enemyAI, because why have 50 enemies checking if they are being looked at every frame, when the player only looks at one at a time?

Hi again :slight_smile:

apologies for the entire month reply, lengthy holiday and only managed to work on this again but thanks to your help I’ve managed to do it in around 5 minutes, simplified and re-done most things but works like a charm :smiley:

posting this incase there is anyone who wishes to copy my blueprints :slight_smile: