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?
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.
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 (NetworkServer.active) { 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.
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.