- Home /
Can't call command from client
I have a GameManager that is part of the starting scene.
It has a NetworkIdentity with Local Player Authority set to true.
On the GameManager I have a script with the following:
[Command]
public void CmdEndTurn()
{
RpcEndTurn();
}
And a button set to with CallCmdEndTurn on press with the GameManager as the object.
When I run the game with a server and client, the server can press the button just fine, but the client gets the error:
Trying to send command for object without authority.
UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
GameManager:CallCmdEndTurn()
UnityEngine.EventSystems.EventSystem:Update()
My only guess here is setting Local Player Authority to true doesn't actually give the local player authority?
Answer by Bunny83 · Mar 12, 2018 at 01:58 AM
Commands can only be send from / to objects a client has authority over. By default that is only the PlayerObject that the server spawned for each player. The PlayerObject is meant as the main communication channel for the client. Only a single peer can be the "owner" of a networked object and have aothority over that object. By default all objects besides the player objects belong to the server. So a client can't just send a command to an object owned by the server. You have to send the command to the playerobject and have the command method on the playerobject on the serverside do whatever it should do. This gives the server the chance to verify the command from that particular player.
You may want to have a look at this manual page:
Commands
Commands are sent from player objects on the client to player objects on the server. For security, Commands can only be sent from YOUR player object, so you cannot control the objects of other players.
I'm just wondering….isn't it unsafe to do the second method? I've just changed my code to the second mthod…. But what about hacking?
Your answer
Follow this Question
Related Questions
[UNet] How I can send Command to non-player object? 1 Answer
Can I use Rpc Calls and Commands on the same object? 0 Answers
UNET Server not setting [SyncVar] 0 Answers
Trying to send command for object without authority. - change color of object from client 0 Answers
SyncListString not changing in a Command 0 Answers