Other
[Command] giving error: Trying to send command for object without authority
So I'm trying have my server change some bools specific to my player controller, and I'm pretty sure the code works, but I think something is wrong with my components. My player prefab network identity doesn't fix it when I uncheck local player authority. The bools effect the mesh renderer of my playercontroller and children of my player controller prefab(two cameras, and a mesh renderer)
Here's the full error:
Trying to send command for object without authority. UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String) PlayerController:CallCmdJoinRedTeam() UnityEngine.EventSystems.EventSystem:Update()
Here are the voids:
[Command]
public void CmdEnterSpectateMode()
{
PlayerCameraEnabled = false;
PlayerIsVisible = false;
GravityEnabled = false;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(500, 30, 675);
}
[Command]
public void CmdJoinRedTeam()
{
PlayerCameraEnabled = true;
PlayerIsVisible = true;
GravityEnabled = true;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(617, 10, 500);
PlayerBody.transform.localRotation = Quaternion.Euler(0, -90, 0);
}
[Command]
public void CmdJoinBlueTeam()
{
PlayerCameraEnabled = true;
PlayerIsVisible = true;
GravityEnabled = true;
PlayerBody = GameObject.Find("PlayerController(Clone)");
PlayerBody.transform.position = new Vector3(383, 10, 500);
PlayerBody.transform.localRotation = Quaternion.Euler(0, 90, 0);
}
Does anyone know how I can fix this? Thanks in advance.
Every player object has own network id. I think, you can't reach them with GameObject.Find function. If you are new to networking, i suggest this video tutorials. It is pretty good. I watched it and after that i understand most of basic networking stuff.
That's a great tutorial series that I've been watching but that's not the issue. It worked before I added the [command] to the void. And just to be sure I removed that part of the code and still get the same error.
Yes. I'm trying to have it so when the local player clicks a UI button they move position and their camera properties change depending on which button they click
This kind of sucks, because even after I managed to get rid of the error, the bools aren't changing :( The player moves into the correct position but the bools stay the same
Answer by AurimasBlazulionis · Dec 10, 2016 at 07:47 PM
It does not matter if LocalPlayerAuthority is checked or not. You can only call commands on player objects. So, if you want to call a command, the component has to be attached to the root of the player.
To check if you are OK on the client side, do Debug.Log(isLocalPlayer)
. If it returns false, then it is not your player. If you are writing a customized NetworkManager, you could be not giving the authority to the player.
Can you really not access components on children of the playerprefab? That seems odd, and It messes up the camera on my playercontroller for looking.