How to make multiple actors use one widget?

I have enemy ai that i want to use one health bar widget i created when they are active. Seperately, it works fine but it doesnt seem to want to work when checking to see if one or the other is active at different times. How can i fix?

(To make more sense, I want 1 to show the health when 2 is dead or not in the level and vice versa)

Hey @oAnubus!

So you want one health bar widget to… Be like a total health bar for multiple enemies combined? Or one health bar per enemy? Like 100 and 100 hp? Or 200hp on that health bar split between both enemies?

1 health bar widget per enemy but using 1 widget

Okay. So there needs to be a way to differentiate, typically this means attaching the bar to the character bp itself by adding a 3d widget (that would typically mean a floating health bar above their head) to the AI. If you want it to be part of the player’s on-screen, stationary UI you’ll need to be able to use some sort of targeting capability.

You can maybe use the last enemy you hit, or the closest enemy etc.

Basically, can you describe how you would like it to appear in-game, and how you would trigger the bar appearing? And how you would like to prioritize enemies?

So the health bar is for the boss enemies in my game. They wont be all in one place at the same time so its just figuring out how i can show the health bar on screen when the main character runs into that boss fight

If you mean like old Nintendo bosses where their health bar just appears on the HUD when the hero enters the boss room, you could probably do that with more than one health bar variable.

In your picture it looks like you are trying to bind more than one character’s health to a single bar.

Hi!

You could dispatch an “event” when the AI activates. Then, you could listen to this event and updates the widget using this AI’s health value on a health bar. After that, during the fight, when the AI receives damage, you could have another event that, when dispatched, updates the health bar. I’m not sure if this is what you would like to do, but If you like this solution, have a look at “Event Dispatchers”.

Hope this helps

I want it set up just like old nintendo boss’s to where you walk in and then their health show up. In my pic, the variables are different, they a referenced from 2 different actors.

This seems a bit much. The health bar is already functional but thats if i plug in one or the other. I needs to work when one or the other boss show up. This is currently what im trying to figure out.

So, like this?

1 Like

I did a little project in the hope that you won’t find it “too much” to use Event Dispatchers.

In my GameMode, I added a EventDispatcher like this :


You see? I’m using an “Already made” widget for my health bar, But I show it when the event is triggered.

I made a little “Trigger” to Dispatch my Event :

And when my character collides with it, I add dispatch the event :

This way, you can have 1, 2, 3, N character that triggers the event…

Cheers

2 Likes

DaSt45 had a post here on how to attach both enemies to a single health bar in case you wanted that option too. I’m not sure why they took it down, but I thought it looked fun.

1 Like

Yeah, I deleted it when I saw that the person wants 2 healthbars.

So here’s my new solution:

Have a Event Dispatcher that updates health on a Health bar.

In my GameMode (where I show the widgets):

For this example, I’ll just print the character name. Notice that I pass it in a param, so I don’t have to duplicate the code.

From that character, when I receives damage, I can call that event dispatcher :

For this exemple, I’ll use the Space Bar…

What do you think?

Cheers

1 Like

Hey again @oAnubus! And welcome to the forums, @DaSt45!

Let us know if you give those suggestions a try, and we’ll try to help you if you get stuck! @DaSt45’s solution above this one should work! If you have any issues, you can take a look at the documentation on dispatchers here. I really, REALLY suggest, if you haven’t learned everything on this specific page I’m linking… please do. It will make your time with UE5 so much more enjoyable, it’s so often looked over but amazingly helpful.

1 Like

This is the best explain the issue. Think of these levels as 2 different levels created in my project. Inside level 1, the bosses health works perfectly fine and everything and disappears on boss death. In level 2, the same thing happens but in order to get the health bar to show in the 2nd level, i would have to disconnect the first boss reference from the return node. Im trying to figure out how i can have them both show without disconnecting 1 or the other from the input node.

(They both work fine but only one can be plugged in at a time)

Ah, that explains it. You really do need an event dispatcher for that then! I guess DaSt45 wins this round.

Have an event dispatcher in the widget and bind functions in the bosses that adjust their health.

Okay, call this function whenever the boss takes damage. It is in the widget blueprint with the event dispatcher:
WidgetForBoss

This can be in both of the boss blueprints (I’m assuming the player’s HUD widget is in the player character, but if it is somewhere else do whatever you need to to get a reference to the HUD widget inside the boss blueprint):

Can you show everything step by step because I’m kind of lost now. I know little to nothing about event dispatchers.

Can we see the complete function you are using when your boss takes damage? And is it inside the boss blueprint or the player blueprint? or elsewhere?

I know little to nothing about event dispatchers.

It’s like this:

  1. There is a blueprint somewhere with an Event Dispatcher. This blueprint can CALL its Event Dispatcher whenever it wants by simply using the call function.
  2. Any other blueprint that feels like it can BIND events to the dispatcher. There is no limit to the number of other blueprints that can BIND whatever junk they feel like to the dispatcher, and the blueprint with the dispatcher has no idea these other blueprints even exist. It has no interaction with them whatsoever. However, on their end, these blueprints that have bound functions are very much aware that the event dispatcher exists.
  3. Whenever the blueprint that owns the dispatcher chooses to CALL the dispatcher, every single event that is bound to the dispatcher goes off far and wide.

So, the solution is: Put an event dispatcher inside your widget and CALL it whenever you want the boss to take damage. It doesn’t matter which boss. The widget doesn’t even know a boss exists. It is just using a call dispatcher node that says “if anything happens to be bound to this, execute now pls.”
In both bosses, have a function in them that changes the health bar. Bind this function to the dispatcher so it goes off when called.