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 .