- Home /
"Trying to send command for object without authority" problem.
Hi guys, if I call a [Command] from a client (which isn't the server-client) the console says "Trying to send command for object without authority"... How can i fix this problem? Thank you.
This is my code:
void Start () {
motor = GetComponent<PlayerMotor> ();
CmdSpawnGO ();
}
[Command]
void CmdSpawnGO(){
GMdad = Instantiate (GM, transform.position, transform.rotation);
NetworkServer.Spawn(GMdad);
}
}
(GM is the GameManager Prefab and GMdad is a private GameObject variable).
Answer by Bunny83 · Jan 08, 2018 at 01:19 AM
Only one player can have authority over a certain object. So it's not possible to have an object being controlled by several clients at the same time. The usual communication channel for players is the player object. This object is usually the only object a player can "control" (send commands to it).
A normal player can not send commands to objects that are owned by the server or by other players. So your script has to be attached to an object that the player owns. Also keep in mind that Start will be executed on every peer when the object is instantiated. You probably want to call "CmdSpawnGO" only on the owning player. So check hasAuthority before you call your command.
void Start()
{
// ...
if (hasAuthority)
CmdSpawnGO();
}
Though instantiating a gamemanager for every player seems a bit strange. Are you sure you want to have one gamemanager instance for every player? If not you shouldn't instantiate it from a client.
I instantiate it beacause he has attached the Inventory $$anonymous$$anager Script, the Icons Script (which stores all the icons of the game) and the Construction $$anonymous$$anager Script (which manages the construction of buildings such as furnaces, walls, etc). $$anonymous$$ay I change way to execute these main functions? Should I create another GameObject? Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612150022im_/https://answers.unity.com/themes/thub/images/avi.jpg)