Enemy healthbar is being shared by all enemies

I’m trying to create a diablo style “hovering over enemy shows their healthbar at the top” mechanic, I’ve got it mostly setup but it’s only showing the healthbar for one enemy even when hovering over another one.


2022-08-01 17-36-33.mkv (5.1 MB)

Hi there,
Get actor of class will not work if you have multiple actors in the level. It will pick a random one. You want to pick the exact reference of your enemy from the output Touched Actor.

1 Like

you are getting reference to a single actor from that class.

you would need reference to every actor of that class, or a specific one (like the one you are hovering over.)

How would you go about doing that? I’m still quite new to unreal and referencing is something i’m not too strong with.

do you have some logic already to do something when enemy is hovered?

if so, the on hovered event probably returns reference to the hovered actor. You can take that variable and pass it to the Get Percent function.

When you have a function selected look in the details panel, you can add an input. Just set an “actor object reference” as input, then when you call the function you can pass the reference in.

I’d share some pictures but i dont have my workstation right now. I’d be surprised if there isn’t some youtube video showing something just like this though, if you prefer to see visually what to do.

The first image is my event for when the mouse is hovered, would the Skeletal Mesh Ref I have be good to use for this? It’s set here. Or would it have to be something of the “Bind Event On Begin Cursor Over”?

Hi there,
It is hard to tell without the rest of your code, but try to get the “touched actor” instead.
Are you following a particular tutorial on this?

i’d use the Begin Cursor over event I think, because that should give referene to the actor.

Not sure how you are managing the widget though. Where does it live? Is it part of the enemy class blueprint?

I have an Enemy BP that stores the health, A health widget that has the healthbar and casts to the viewport and a component that controls all the hovering and clicking on the actor that I have then added to the Enemy BP.

No I’m not following a tutorial on this

So, after the touch event, add a branch and get Touched Actor and connect it to an equal and get a reference to self. So, the widget will only update if the touched actor is equal to the “self” reference.

c3b32ce04c37b90e90398a99f53c66f0
Something like this?

1 Like

I believe that should work.

How would I then reference this in the Widget though?

The health is going to be updated after the branch “true” path. If the widget is already visible, assuming is an actor widget, just send the information you want. Get widget component, then get widget (a green function), and cast to your widget BP. Set the variables you want.

Are you causing damage on hover? Or are you selecting as a targeting system? If so, you want to send the hovered actor to the player character as well after the “true” branch, get player character, cast to your character BP, then set current target as that “get reference to self”.

Sorry I’m struggling to follow this. After the branch is true, I cast to the health bar widget? I currently have it going from True to Adding to Viewport but that isn’t showing up.

I’m using it as a targeting system, you hover the mouse over the enemy and a red outline appears and shows the health bar of that enemy.

Are you not using an actor widget? That is the best way to make health bar individually.

Show AI Health Above Head | Floating Widget | Improved - Unreal Engine 4 Tutorial - YouTube

No I’m using a widget blueprint. Would I be able to have an actor blueprint at the top of the players screen?

An actor widget. That video shows the steps. Hope that helps.

Okay thank you for your help, I’ll try that out!

1 Like

LFA has explained in simpler terms than I could.

basic idea is that each actor has their own widget. When the actor is hovered over, they just make the widget visible.

This should be easier to manage versus sending data to a widget, which then has to track that actors position constantly. You could do it that way of course, but it’s just more data to pass around and manage.