assignclientauthority - Unity3D.Trying to send command for object without authority





[command] specific (5)


Problems with Network Transform Component

If You want to sync position/rotation of the non-player object across your network then, before performing position/rotation you have to assigned that non-player object authority to your player. For details you can check my this answer

I have a multiplayer turn-based strategy game that needs a game manager, controlling current game state (who's turn it is etc.). This manager should be common for every client, it's state should be synchronized on server.

Here's how I'm doing this: The game manager object is NetworkBehaviour and it has NetworkIdentity which is not local player authority nor server authority. I've made a custom NetworkManager and it spawns the Game Manager on client connect, also testing if it is a server. Here's a code:

public override void OnClientConnect(NetworkConnection conn)
    {
        ClientScene.Ready(conn);
        if (NetworkServer.active)
        {
            var manager = Instantiate(MultiplayerManagerPrefab, Vector3.zero, Quaternion.identity) as GameObject;
            var tacticsManager = manager.GetComponent<MultiplayerManagerModel>();
            NetworkServer.RegisterHandler(MsgType.AddPlayer, tacticsManager.CreatePlayerOnServer);
            NetworkServer.Spawn(manager);
        }
        ClientScene.AddPlayer(0);
    }

When I run it on a server it works fine, it creates an instance on a client and synchronizes variables from server to client. But when I try to run commands from client it ignores them, throwing this warning:

Trying to send command for object without authority. UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)

Note that this Game Manager is spawned before any player is because it must be responsible for spawning players. What am I doing wrong?




Unity : Trying to send command for object without authority error when more than one client is connected

Well this is the problem which i usally get when first i were learning UNET. So here is the general answer and i am sure it will solve your problem once you get that How UNET actually work.

Beside your code fragment, the error

Trying to send command for object without authority.

clearly means that you are sending Command request from an object whose authority you don't have.

So What it means and how to resolve it you can see my answer Here.

According to your code fragment, Before sending the command (or executing command function), Assign authority of that object(where your script attached) to your Player.

hope that it will make sense and slove the problem. Cheers!




You can't send a command without local authority.

if (!isLocalPlayer) return;

But, what kind of data are you sending with this command ? In general, and as you said :

"it's state should be synchronized on server"

So, IMHO, you have no reason to send a Command from your player. Commands should be for player input. These inputs will trigger actions in your game. Your manager will get informations from these actions (score update, end of the game...) and send data and/or trigger actions on clients, using ClientRpc

This is the server authority model. If you let a local object send commands, a hacker could easily come in and say to your manager

"Hey, it's my turn. Hey, it's my turn again. Hey, my score is 9999999 and I won the game in 1 second.".




unity multiplayer control not working

In UNET, Before performing any operation into non-player object you have to first acquire its authority. After getting the authority, you will become able to perform an action that will sync across network.

For details You can check my this answer.




Unity 5.3+ Networking Load Next Level

I am able to do this through an additive scene loading i used this code.

[ClientRpc]
    public void RpcLoadLevelAcrossNetwork() {
        SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);   
    }

ClientRpc will load the new scene to all connected clients and additive scene loading will allow you to preserve camera/player GO/health etc