How does the server- and client-side players list work?

For experimentation purposes, I tried commenting out the list addition in RTSPlayer.OnStartClient:

public override void OnStartClient()
    if ( { return; }


    // ((RTSNetworkManager)NetworkManager.singleton).Players.Add(this);

With 2 players in the lobby, this is what the host’s screen looks like:

And the non-host player’s screen:

Why doesn’t the host’s screen match the client’s? I thought the host’s RTSPlayer script running on the client would update the player list with ClientHandleDisplayNameUpdated, but the player name list is still displayed on the host (like it is using the server player list instead of the client).

Also, why isn’t the code in OnStartAuthority instead of OnStartClient? I assume OnStartClient is called on both Player 1 and Player 2’s client when the RTSPlayer component is added to the player GameObject. Will the player be added to the list twice?

Hi there, good questions!

The server adds players to the Players list in OnServerAddPlayer in the netowrk manager, so the server’s network manager always has the correct list of players.

In OnStartClient, we are updating this list for all instances of the game that are not servers. Since this is only called in OnStartClient, it is only called by the NEW player being added, and not by all players. So essentially each player adds themselves to the client list as their player appears on the client. This means it will only be added once.

Hope that answers your question!

1 Like

Thanks for the response!

I do see the player GameObject (DontDestroyOnLoad) instances on the host hierarchy. OnStartClient documentation says: “Like Start(), but only called on client and host.” Since host is a server and a client, why isn’t this called on the host?


Also, is the NetworkManager shared/synced across all players? Will adding to the NetworkManager singleton sync across all players?

You are correct that OnStartClient is called on the host. I only meant that this is the method used to add the player to the Players list in the client only instances. I believe the check:
if ( { return; }
in OnStartClient, prevents the player from getting double added on the server. I believe this is a check that we are in the server. Hope that clarifies this.

All of the NetworkManager data is not synced by default. Many of the Mirror features are synced across the network, but data you create will need to be manually synced using syncVars etc.

1 Like

Thank you, that makes sense! I guess you could also remove the player addition in OnServerAddPlayer and remove the server-only check in OnStartClient.

I could also try putting a SyncList Players list on the server and seeing if that is synced across clients and remove the player addition in OnStartClient.

1 Like

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

Privacy & Terms