Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AssignClientAuthority - When is authority completely assigned?

Discussion in 'Multiplayer' started by Skerbey, Oct 15, 2015.

  1. Skerbey

    Skerbey

    Joined:
    Oct 15, 2015
    Posts:
    11
    Hello,

    In my multiplayer scene players can spawn cubes and when one of the players clicks on any of the cubes I assign client authority to them, parent the cube to the players head and calls a command on the cube to freeze its rotation in the RigidBody Constraints. This runs fine on the host however the issue I came across was when a client attempts the same action I get an error saying that It doesn't have authority to run the command. I noticed that I could run the command on the cube in later Update() calls. So I then implemented a timer that waits for four Update() calls and then calls the command on the cube to freeze rotation. This workaround doesn't satisfy me though.

    TL;DR It seems that client authority is assigned immediately on calling it, however I cannot call commands on the newly reassigned object until 4 Updates() have passed.

    So I guess my question is: Why don't I have authority to call commands on a newly reassigned object and what is actually going on with AssignClientAuthority?


    Cheers,
    Skerbey
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    OnStartAuthority is called
     
  3. Skerbey

    Skerbey

    Joined:
    Oct 15, 2015
    Posts:
    11
    Does OnStartAuthority on the NetworkIdentity component set the clientAuthorityOwner and add the object to the clientOwnedObjects list?
     
  4. Skerbey

    Skerbey

    Joined:
    Oct 15, 2015
    Posts:
    11
    I believe I found the issue.

    Before the client would call a command to AssignClientAuthority then after that command would try to access the newly assigned object and call commands on a script on that. It seems that AssignClientAuthority was setting the authority on the server and it took a few updates for the client to receive the update on the authority property and so couldn't call commands until it had been updated. Now I am calling these commands on the object from within the command on the player since the server knows straight away who has authority and this seems to work.

    I do still seem to get inconsistent behaviour from NetworkIdentity.connectionToClient which I am using to AssignClientAuthority to the player. Sometimes it report a connection and other times not and this is affected from changes to seemingly unrelated code. Is there a known issue with NetworkIdentity.connectionToClient?


    Regards,
    Skerbey