Unity3D. Trying to send command for object without authority

Beside your code fragment, the warning

Trying to send command for object without authority.

Means that: you are sending command from an object whose authority, your (player) don’t have.

What Unity docs states: Commands are sent from player objects on the client to player objects on the server. For security, Commands can only be sent from YOUR player object, so you cannot control the objects of other players.

BUT

Starting with Unity release 5.2 it is possible to send commands from non-player objects that have client authority. These objects must have been spawned with NetworkServer.SpawnWithClientAuthority or have authority set with NetworkIdentity.AssignClientAuthority. Commands sent from these object are run on the server instance of the object, not on the associated player object for the client(more).

So what is the solution: Before sending the Command (or executing command function), Assign authority of that object to your Player. Something like this

assignAuthorityObj.GetComponent<NetworkIdentity>().AssignClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient);

this” will be represent to your Player object. After making Command call you can remove authority using this code snippet.

 assignAuthorityObj.GetComponent<NetworkIdentity>().RemoveClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient);

Again, “this” will be represent to your Player object.

Important Note: I usually assign Authority of an object (If I want to use that) using OnTriggerEnter and remove authority on OnTriggerExit. It depend on specific scenario that at what event you want to acquire or remove an object authority.

Leave a Comment