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?