Unity 5.1 networking, Cant get [Command] to work :(

Hi
i am using the latest unity version 5.1.1 f1
and i have been stuck for ages trying to solve a problem which seems to be simple to everyone

i can’t spawn objects to the server no matter what
this is the code

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class InsTest : NetworkBehaviour {
public GameObject testIns;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    if(Input.GetKeyDown(KeyCode.I))
    {
    CmdTestIns();


    }
    }


    [Command]
    void CmdTestIns()
    {
    GameObject tmp = Instantiate(testIns,Vector3.zero,Quaternion.identity) as GameObject;
    NetworkServer.Spawn(tmp);
    }
}

its pretty simple and neat

i have all the components net manager and network identity
and i have add the object to the spawn list

on this object that has this script there is only network identity
i have debugged it outside the game and inside and they all run

first if i was the host the object gets instantiated but only one can see it which is the host

second if i was the client nothing gets instantiated on the host or the client

i have followed the steps very carefully of many tutorials on youtube and unity fourm/answers
this bug just refuses to get solved

UPDATE****************

I changed the script from MonoBehavior to NetworkBehavior

and kept everything the same i faced a problem telling me your object doesn’t have network identity

the thing is that object was the NetworkManager and NetworkManagerHud components

so i removed the script made another object and added network identity with the
instantiate script

it worked with the host if the host instantiates everyone gets it

but if i try to instantiate from the player i get this error
unity trying to send a command for non local player

and it doesn’t work i debugged it this code stops the instantiating
here is a picture of the gameobject

[![[/URL]

UPDATE***********************************************************************
This error is getting on my nerves
unity trying to send a command for non local player

its local player i am 100% sure the instantiate code is disabled if not local
by disabling it as a prefab and enabling it on start i debugged it and i am
100% sure every instantiate script works only on the machine locally

this issue unity trying to send a command for non local player
combined with the fact that isLocalPlayer doesn’t work as it supposed to
its false all the time no matter what it doesn’t recognize that i am running the game locally

they indicate that there is something wrong with unity](http://s22.postimg.org/lpoggvzml/locl.jpg "[/URL]

UPDATE***********************************************************************
This error is getting on my nerves
unity trying to send a command for non local player

its local player i am 100% sure the instantiate code is disabled if not local
by disabling it as a prefab and enabling it on start i debugged it and i am
100% sure every instantiate script works only on the machine locally

this issue unity trying to send a command for non local player
combined with the fact that isLocalPlayer doesn’t work as it supposed to
its false all the time no matter what it doesn’t recognize that i am running the game locally

they indicate that there is something wrong with unity")](http://postimg.org/image/lpoggvzml/)

I am moving this to the correct forum. Teaching is for discussing tutorial and and lessons.

Commands work on local player objects (e.g. the one you have put in the prefab field of NetworkManager). Your client has to have “localAuthority” over that object to send a command. Not every gameobject will send commands.

If you start the server and connect a client, a prefab will be instantiated. That should work. Your “ins”-object is a scene object and not a local player object.

I tried to add the InsTest script to the players
the players are auto instantiated by the NetworkManager
i got the same errors
i checked if i had any reference for InsTest and i didn’t find any
InsTest is being instantiated with the players

i still get the same error

player is not local and

this issue unity trying to send a command for non local player

Hey i solved the issue
turned out my steps were fine but there was some bug if you enable a component after instantiating it
that component wont work
basically i was disabling InsTest and enabling it on the start of the game so the Host will only see his insTest enabled and the clients will only see theirs
i checked if they were true by debugging and they were true for everyone(i used an asset to debug after build)
there were no issues about any local stuff and InsTest was working for everyone

the only issue was if you disable a component and try to enable it inside the game
it will be enabled but it simply wont work except for the host

turns out that unity networking system doesn’t work like photon’s

interesting

thanks for helping you were a big help :slight_smile:

A bit old post but maybe it will help to future users use this

// Update is called once per frame
   void Update () {
  if (!isLocalPlayer) {
           return;
        }
   if(Input.GetKeyDown(KeyCode.I))
   {
    CmdTestIns();


   }
   }

MFKJ, Thanks a lot mate! I’ve had this problem for over a week, and I was really starting to get mad, but you realy helped me. Thanks!