How do I make an HP bar appear for other players in Multiplayer?

You could just add a Widget component with the HP bar on your pawn BP, that way it should show everywhere. Then you just need to bind the appropriate events or create the bindings to update the bar percentage, and it should update on all clients.

Goal is to spawn an HP bar that other clients can see it, not just its own client.

I have tried using the method you mentioned (adding a widget component directly to the character). All characters have bars on top of them. However, when one character takes damage, all of the bars get updated (including the damage causer, which shouldn’t happen). I have no idea of how to access the widget component that I added and how to update it properly so that only the character taking the hits gets its HP bar updated. Can you shed some light on how I would do that? Thank you.

You could add a variable in your HP widget, that is instance editable and exposed on spawn, and the type is that of your base pawn class.

Then in your pawn BP, you could have your widget component have no widget, and on Begin Play of your pawn, you can create a new HP bar widget, and pass a reference to self as the value for the variable that you created above. Then after you create it you can use the Set Widget function to set the HP as the widget of the widget component.

Then in your HP bar widget BP, on Construct, you can create a binding for the percent of your progress bar (I’m guessing you’re using a progress bar for the health), and set the percentage using the values you get from the variable.

If you are calling an event dispatcher on your pawn when health is changed, you could also just bind an event to that in your HP bar BP, so that the binding doesn’t run every frame, but only when health is changed.

340450-screenshot-2021-06-02-013153.png

![alt text][3]

1 Like

Thanks. The creating widget and using a binding is what I have used the first time. I tried to follow along everything you said, but the problem with this method is that if I don’t use a widget component then I can’t spawn a bar that is visible to everyone. Through this method the bar is created for the client only, but not for the other players. Am I doing something wrong?

You should still use a widget component. And then on your pawn begin play create the widget and use the set widget node for that component, and pass the created widget. In my last picture, Health Bar is the name of the widget component on my pawn.

I am getting a little bit confused. Pardon me.

1-You could add a variable in your HP widget, that is instance editable and exposed on spawn, and the type is that of your base pawn class.

Does that mean that I am supposed to add a variable that corresponds to my character blueprint? My character blueprint is BP_SFR, so I made the type of the variable the same as BP_SFR. Also, the variable made is found in the same place as where the HP Bar variable is located within the wdg_HPBAR.

2-Then in your pawn BP, you could have your widget component have no widget, and on Begin Play of your pawn, you can create a new HP bar widget, and pass a reference to self as the value for the variable that you created above. Then after you create it you can use the Set Widget function to set the HP as the widget of the widget component.

By widget component have no widget, I assume you mean that I don’t assign a widget class to it?
I get the create a new HP bar widget, but what do you mean by “pass a reference to self as the value for the variable you created above?” In the picture that you sent, you have a little node that connects self to pawn. When I create a widget and assign it to my wdg (Health Bar), there is only an Owning Player Node.

4-Then in your HP bar widget BP, on Construct, you can create a binding for the percent of your progress bar (I’m guessing you’re using a progress bar for the health), and set the percentage using the values you get from the variable.

When I open the binding and there is get health percent and return node, I can get Pawnz (name of the variable which the type corresponds to my BP). However, I can’t access the Target/Health node from your picture to connect it to Max Health and Current Health.

When I try to set my widget component like you did, I can’t connect the return value to the set widget component, nor can I connect it to Set Widget. Also, what is your Owning Player Node connected to?

Thank you once again.

For the pin to be exposed like in my screenshot, you need to set the variable as “Instance Editable” and “Expose on spawn”. You can do that when you select the variable, in the details panel, in the BP. So, your “Pawn” variable of type BP_SFR should be exposed on spawn in your HP bar BP. Once you do that, you might have to refresh the Create Widget node (right click - Refresh node). The pin should then appear and you can now connect the self reference.

You can leave the Owning Player empty, it’s not required.

In my case my pawn has a custom made health component which handles all health functions, which is why you see the Health node in my screenshot. In your case, you might not have that, so if in your BP_SFR class you have two variables, one for the Current Health and one for the Max Health, you will have to use those.

I’m not sure why you can’t connect the output of Create Widget to Set Widget, I would have to see more of the setup. But as long as your HP Bar widget BP inherits from User Widget it should work.

Let me know if it works.

IT WORKED! Thank you soooooo much man. I have been working on this problem for over 5 hours and your solution finally did it for me (after checking Expose on Spawn and Instance Editable. When you first mentioned them I thought you were just telling me the characteristics of the variable but didn’t realize they were boxes to be checked). Very much appreciated!

Glad I could help :smiley: