How to make multiple actors use one widget?

this is inside all my boss’s Blueprints. If im not mistaken, i would need to put this set up into the thirdperson game mode along with the dispatcher that creates the widget?

i would need to put this set up into the thirdperson game mode along with the dispatcher that creates the widget?

Not at all. First of all, the dispatcher does not create the widget, the dispatcher is INSIDE of the widget. You can make a dispatcher in the details panels of most blueprints.

It would look like this:
WidgetDispatchDetailsPanel

And then, also in your healthbar widget, just have this custom event that does nothing but call the dispatcher:
WidgetForBoss

Here is the possibly tricky part. I have no idea where you are creating your widget. But, wherever that is, it is possible to have a widget variable. You need to get a reference to your widget inside your boss so you can bind the health update to it. Here is how you could do that if you are creating your widget in your player character:

Edit: I realize I also made a reference to the player while I was there. That’s just a habit on my part I did without thinking, the relevant things are just making sure that you have a variable reference to THE WIDGET and that you bind the function to set the health to the dispatcher.

Then, since you have the widget variable in your boss now, all you have to do is use that custom event to make the widget call the dispatcher so it will run your bound function! Just plug this into your current damage function. A good spot would be right after you set “current health” but right before you spawn the particle emitter:
MakeWidgetCallDispatcher

Though you likely already know this, I still figured I would mention how to make the widget variable just because we are being really detailed here. So, in your player character (or wherever it is you are making your widget) make sure to make a variable of the widget after you create it. This is the variable that you are passing to the bosses:

I have the widget showing from the boss enemy itself. Should i add that to my HUD widget instead?

No, that just means it is even easier to get the widget reference.

I’ll type it, I guess pictures aren’t helping :slight_smile: :

  1. In the widget with the boss healthbar, create an event dispatcher. You can do this by going to the bottom of the details panel and pressing the plus sign next to “event dispatchers.” Name the dispatcher whatever you want.

  2. Then create a custom event in the same widget. Pull out from the execution pin and type in “call” in the node search. There should be a node that allows you to call the event dispatcher you just made.

  3. Go into one of your boss BPs. Pull off the string from your create widget node (so, the same spot where you pull the pin to "add to viewport) and create a variable. Do the same thing in the other boss BP.

  4. Still in the boss BP, at that same spot where the widget creation node is, now pull off from your variable and in node search type “bind.” There should be a bind node for the event dispatcher you made in the widget. Do that in the other boss BP as well.

  5. Off of that bind node, there should be a red pin on the LEFT side. Pull out from that and it should make a custom event node for you. Call the custom event whatever you want. Then get the widget variable you made earlier and pull out from it. Get the variable for the healthbar itself out of the widget. Now pull off from that healthbar variable and node search for “set percent.” Use that node to set the percent of the health bar to “current health” divided by “max health.” Then go do the same thing in the other boss BP.

  6. Now go to your damage function. Drag out your widget variable and from it pull the pin and node search for that custom event you made in step 2. Plug that into your damage function at some point after the health variable has been changed. Do the same in the other boss.

Your widget should now work for both bosses. :slight_smile:

Edit: I’m assuming that the healthbar in the widget is specifically a “progress bar.” If it isn’t, then first make a progress bar to be the health bar and do the above.

Ok, I understand a bit better, thanks!

Your widget “depends” on an “actor”. You just need to “decouple” that widget and make it generic! Think of your widget like a tool that can be used by whatever actor.

When you read the “current health” and the “max health” from the actor, this is in fact all you need from that actor! So, let the actor give that information to the widget!

There are many solutions possible and I think you find it hard to work with Event Dispatchers. So, let me try a new approch, using a function. And I’ll do it in a video if that can help you, have a look :

https://youtu.be/4iXi4hhGvEw

Do you agree that my health bar can be used by any “bosses” ? since I don’t depends on one?

In the video, when my “Boss” gets damage, you could trigger an Event to whom wants to hear it… or, if you get an instance of that widget, call it directly with a public function. I like to decouple as much as possible, but this solution is also viable for what you showed us.

What do you think? Does it help?
Cheers

This is exactly what i was trying to do. I didnt feel the need to use an event dispatcher because i just felt like what i already had was missing something or i skipped a step. The only thing i had to change into my boss blueprints is how the health is showed but other than that, it worked perfectly fine and tested it well. Thanks for the help!

1 Like