"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).

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();
}