Multiplayer 1 vs 1 replicated User Interface

Hello .
I am trying to make a User Interface for a 1v1 multiplayer ( not local ) , in which both players are clients and both see each others remaining health on their user interface .
I have coded what I thought was the right code for this , but unfortunately this doesn’t work and I don’t know where I am going wrong .
I will show what I have done with some pictures and graphs , so hopefully someone can tell me where I went wrong .

First of all when I press play with “numbers of players” set to 2 , it spawns 2 servers and 4 clients , is that normal ?

First of all this is the widget that I am talking about and it contains 2 progress bars at left and right .This widget is created for both players at runtime .

I am spawning players from player controller with an RPC to GameMode (which is named SR_SpawnPlayer and is set to “Run on Server” , then I set the camera , then I create the widget and save it in UserInterface variable . here is how it looks like :

https://blueprintue.com/blueprint/kp1fyilg/

Shown below is GameMode which has 2 functions , FindPlayerStartPositions and SpawnPlayer.

Shown in below picture is a look at the FindPlayerStartPositions function . I have 2 player start position in the level named Left and Right which this function will find and assign them in a variable.

And here is inside of the SpawnPlayer function , I use the previously found player starts to place created players , and then set the “IsLeftPosition” bool to true for the first controller/character , so i know which player is left and which players is right .

https://blueprintue.com/blueprint/q5cznd79/

Then in the Character blueprint , I have replicated Health and MaxHealth variables depending on being the left or right position, And there is a simple setup to damage the player by pressing “Z” on keyboard and checking if the player is positioned left or right , which eventually calls UpdateHealthUI function . ( this is probably where I mess up )

And here is a peek at the UpdateHealthUI function in which I pass the data to the main widget that contains the health bars :

And lastly this is the Graph for the main widget which receives the data and sets the percentage on the progress bar !

Sadly this doesn’t work and since my multiplayer knowledge is lackluster I do not know how to fix this . Can a kind soul please tell me what to do and where I went wrong ?

Thanks in advance .

Why do you have HP for both players in one character?
Just use one, they will keep their own HP.
And for Health bars, just bind them to get HP from the characters.

Yes. If you look at the appended number to BP_ThirdPersonCharacter there is only 2 instances. 0 is the first character and 1 is the second character.

The server has spawned Character 0 and Character 1 and replicated them to client and client 1. This is why you see 6 Characters in total.

Lets say I am at left side , I need to know my health and other players health to set both of the progress bars on user interface , because the UI shows both players health .
So how do i do that with just 1 health variable ? can you please elaborate ?

Thanks for the explanation .

1 Like

Each Player can just hold there own health variable.
If you are wondering how you can determine who is who, just use actor tag.


image

image

Thanks alot .
I was able to get it to work with your guidance .
i realized 2 of my “BLUEPRINT UE” links were not showing in my post , so i just added the link , you can see the spawn function now .

Since i wanted the player to choose left or right , i didnt want to add actor tag to character before runtime , so i tried adding it at runtime , when spawning the player in the GameMode . but i realized actor tags are not replicating and only server has the tags and not the clients, so i just used the IsLeftPosition variable to determine which one is left .

Thanks again .

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.