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/)