Search Unity

Custom network manager player spawning without local player authority

Discussion in 'Multiplayer' started by Cait, May 23, 2017.

  1. Cait

    Cait

    Joined:
    Oct 16, 2015
    Posts:
    1
    I have created a custom network manager which derives from the NetworkManager class. I am trying to create a "character selection" menu in which the user can select a character they would like to play via a button. So I am setting the playerPrefab after the user makes this decision. Here is the relevant code:

    [SerializeField]
    private GameObject playerK; // this is the prefab of the character to be instantiated
    ...
    public void pickCharacterK()
    {
    ClientScene.RegisterPrefab(playerK);
    playerPrefab = (GameObject) Instantiate(playerK);
    ClientScene.AddPlayer(client.connection, 0);
    }

    The idea was that ClientScene.AddPlayer would call OnServerAddPlayer on the server, and that would create the player object with local player authority. What actually occurs is that the character prefab is instantiated as a remote player, so it doesn't have local player authority. You can see it on the map, but the player can't control it. I also get the error "Unkown message ID 37 connID:1" which I gather means that the AddPlayer network message is not registered, and I need to use the RegisterHandler function somewhere. I'm just not sure where, and what should be the parameters of that function call.

    I have also tried overriding the OnServerAddPlayer function and instantiating the prefab in there, but this has a similar issue where the instantiated player isn't controllable.

    It seems like the issue is that the player object is instantiated on the server, but not the client. And because my computer is acting as a host, you can see the player object on the server. Any suggestions on how to fix this issue?