Search Unity

Help Wanted Trying to send command for object without authority

Discussion in 'Multiplayer' started by gamer123454321, Dec 13, 2020.

  1. gamer123454321


    Mar 25, 2020
    Hi! sometimes use [Command] on a method has no problem, but sometimes has error message "Trying to send command for object without authority". Can anyone tell me why? When is Ok to use [Command]?
  2. DasMaeh


    Oct 18, 2017
    The following answer is specifically for the case you use Mirror as your underlying technology. But because Mirror bases on UNet it could also be conceptually identical to Unity's "vanilla" solution.

    In a Network Game, each GameObject exists on all machines(the server and all clients) participating in the game session. Therefore and in general, ALL machines execute ALL code attached to these GameObjects. The moment you add the NetworkIdentity Component to a GameObject it becomes synced over the network but this rule only counts for attributes specifically marked as being network-synced! Let's assume Client A moves an Object downward and Client B moves it upwards at the same time, which position is the correct one for Client C?
    To solve such conflicts, there can only be one machine with authority over a GameObject, and only this machine is allowed to instruct others about what to change and by how much.

    To make a long story short... the [Command] keyword tells a function that it will only be executed on the server. But it also tells the function that only the machine with authority can call this function! Execution calls from others are refused. And exactly this denial happens every time you get your message printed in the console log. There are now two solutions to it: (a) use [Command(ignoreAuthority = true)] or (b) check and get the authority before execution

    Option A is probably not the correct one for you. It might work but can lead to some other problems. It is a solution you should only go for if your game concept requires it.
    Option B is probably the "correct" solution.

    Nevertheless, it is very important that you understand the concept of authority before continuing the path of developing a multiplayer application.

    Some useful links:
    hyouuu, ss3yuvan, apot5720 and 2 others like this.