[Multiplayer] Get player array & set it on UMG for both server/clients

The script only prints the host’s player name. Clients aren’t being produced on the server nor other clients.

How can I get this to work properly?
Do I need to be running something on server?

Thanks in advance!

1 Like

Player States dont all get created on the first tick.
Instead of constructing your list only once when this actor is constructed, I would recommend setting your player state class to tell your list to update once the Player state Beginplay is called, on server side of course, and each time it updates server side, replicate to all clients.

Thanks for the reply and advice, Enigma. I have one follow up for you. If a player leaves the game by just exiting out of the game client all together, how would I have that player removed from the list? I understand there is an option to set how long a playerstate sticks around after leaving. Would this be the option I’m looking for?

I actually dont know the answer to that question, but I would do the following:

  • in PlayerState destruct function, tell server to multicast that the list of players should update.
  • set a timer to every 2 seconds ish, multicast that the list should update. That way if a client’s computer gets destroyed by a lightning bolt and therefore cannot call the destruct function, it will still update the list to remove the missing player’s name.

Are you found a solution to replicate playerarray to clients?

And remember, the PlayerArray is already replicated, so don’t send it over the multicast RPC; just use the one the Client already has.

One way you can make sure the client doesn’t update the UMG until the server side version of the PlayerArray has changed, is to put a repnotify variable on the PlayerState class, and update the UMG as part of the repnotify function. you can change this variable any time the list should change.

1 Like

This^ Great thinking Mighty