Search Unity

AssignAuthority doesn't work.

Discussion in 'Multiplayer' started by Slack43, Jan 28, 2019.

  1. Slack43

    Slack43

    Joined:
    Dec 23, 2015
    Posts:
    68
    Hi, i have a script which spawns player in a lobby. Players are spawned by a non-player object. To spawn them i need to assign client authority to this object.

    So i do it like that:

    Code (CSharp):
    1. CmdAssignAuthority(lm.gameObject);
    2.             print("before: " + lm.GetComponent<NetworkIdentity>().hasAuthority);
    3.             lm.CmdAddPlayer(nickname, uniqueID, this.gameObject);
    4.             CmdRemoveAuthority(lm.gameObject);
    5.             print("after: "+ lm.GetComponent<NetworkIdentity>().hasAuthority);
    This are the CmdAssignAuthority and CmdRemoveAuthority commands:

    Code (CSharp):
    1. [Command]
    2.     public void CmdAssignAuthority(GameObject go)
    3.     {
    4.         //NetworkIdentity netID_ = go.GetComponent<NetworkIdentity>();
    5.         //netID_.AssignClientAuthority(connectionToClient);
    6.         go.GetComponentInParent<NetworkIdentity>().AssignClientAuthority(this.connectionToClient);
    7.     }
    8.     [Command]
    9.     public void CmdRemoveAuthority(GameObject go)
    10.     {
    11.         go.GetComponentInParent<NetworkIdentity>().RemoveClientAuthority(this.connectionToClient);
    12.         print("removing authority");
    13.     }
    As you can see i log if the player has authority over the object.

    Both before: and after: are false in the console.

    I have a headache because of that ;)