In multiplayer mode can't get other character's player ID of other clients in current client

I have a dedicated-server setting of the game with three clients, after each character joins, I would love to assign a player id to that character with “textrender component” above the head of the character, and all other existing clients can also see others players head text (sync or replicate to other clients).

Currently, I can only see the player ID in the current client. I understand that I can get the new player in onPostLogin event in GameMode and add it to a variable in GameMode, but fails to read the array in GameState and other places.

Player Controller only exists on the server and on the client where it is used. Other client cannot access it, even if you try to pass it as a client/multicast parameter.

I ended up converting UniqueID to string, and transferring an array of strings to each client, where strings are converted back to UniqueIDs that are used to retrieve data.

1 Like

A common place to put this sort of thing is in the PlayerState. The GameState is replicated to all clients and the GameState contains a PlayerArray which contains all of the PlayerState’s. PlayerState has functions like GetPlayerName and SetPlayerName. Give that a shot and see if it works out for you.

1 Like

It seems that I can get all other players’ player IDs through PlayerArray in GameState, but I’m not quite sure how I can correspond the IDs to other clients in my current client, and once a new player joins, would their ID be synced to all clients?

Access player IDs in PlayerState blueprint:

Each pawn has a replicated player state variable. That will give you access to the playerstate for each pawn on each client.

Player Id is a replicated variable as shown by the two white bubbles on the right of the node. This means it is synced to clients as soon as they join.

Controller, PlayerState, and Pawn are always tightly knit together. You can juggle between them like so :

Note that in multiplayer on client-side, the controllers of other players and AIs are not available (they will be null).

Also note that the pawn/character may be null if the specified player is not alive at the time.

This is why PlayerState is the best place to store such player-specific data that is not bound to a specific character and needs to be accessed by everyone.