I have a client server build in Unity 5. I want to send a command from the client to the server with a GUI button click, this is for testing purposes. So on my client all I want is to click a button and then have the server display a message on its console window. Reading through http://docs.unity3d.com/Manual/UNetActions.html this seems to require a player object. With the demo I am trying to create there is no player. So I created an empty game object and called it player and assigned it a player script:

public class Player : NetworkBehaviour {

void Update () 
{   //receive message from camera follow script to run command from client to server
    if (isServer)

    if (GameObject.Find("Main Camera").GetComponent<CameraFollow>().sendCommand) 
        CmdTurnOnNetworkTransformOnServer ();

void CmdTurnOnNetworkTransformOnServer()
    UnityEngine.Debug.Log ("Received");

This script checks if a boolean is true on another script (the script that contains the GUI button that when clicked sets the bool to true). if it is true then I would like the server to display "Received" on the console in the editor. However I get the error "Trying to send command for non-local player." From what I can see I am following the above link properly to just display a simple message. I realise there is another route with http://docs.unity3d.com/Manual/UNetMessages.html however I would like to see if I can get a command working instead.

Full Error: Trying to send command for non-local player. UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String) Player:CallCmdTurnOnNetworkTransformOnServer() Player:Update() (at Assets/Player.cs:37)

How come I am getting this error?

This error appears in the client console window

  • \$\begingroup\$ Maybe it is being called on a non-local player? \$\endgroup\$ – andeart Feb 1 '16 at 19:42
  • \$\begingroup\$ @andeart could you expand on this? What am I missing or not doing? I don't understand \$\endgroup\$ – CH99 Feb 3 '16 at 9:10

Reading through http://docs.unity3d.com/Manual/UNetActions.html a player object is required. This player object should be a prefab and fill the space beside player prefab under spawn info within the network manager script in the editor. I created an invisible player object, so it may aswell not be there, but for the purposes of sending a command it should be. This avoids the error of sending a command for a non-local player.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.