OnServerAddPlayer not called on client joining?

I’m trying to set a name for a player and I do the logic of assigning the name (Not the syncing which happens in other code) in the OnServerAddPlayer method which takes the name from a text input. It all works when I write a name and host a server, the problem happens when a client joins the hosted server, it manages to get the host player name but it doesn’t set his own name - meaning the OnServerAddPlayer didn’t executed when the new client is joining - I ran a debug and found out that It really doesn’t call it.

Any suggestions where should I put the logic of getting the name out the input field and setting it on the player prefab instead on OnServerAddPlayer?

OnServerAddPlayer is called on the server every time an AddPlayer message is sent to the server. The clients will not run it. I’m assuming you are allowing the clients to set their own names before they join a game in which case you could have the NetworkManager store the players name when StartHost() and StartClient() are called and attach a NetworkBehavior script to the player that grabs this value for the local player and syncs it.

Is that what you intended to do?

Edit: Use this function to set it on the local player:

public override void OnStartLocalPlayer()
2 Likes

Thanks! overriding OnStartLocalPlayer in my player setup script did the trick :slight_smile:

1 Like