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)
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?
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.
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”.
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.
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.
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.
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.
Okay, call this function whenever the boss takes damage. It is in the widget blueprint with the event dispatcher:
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):
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.
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.
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.