- Home /
The question is answered, right answer was accepted
NetworkServer.Spawn not working with no error message
Hey guys! I know this might be a common problem, but I couldn't find anything I hadn't already tried anywhere.
Basically, my prefabs get instantiated properly on the host but NetworkServer.Spawn() doesn't seem to do anything since they never appear on the clients. I've tried registering the prefabs manually in the editor and in code on the server (I wasn't sure if it had to be called on clients too), but nothing worked.
I only get a warning if I add a NetworkTransform to the object and make it move: Did not find target for sync message for ID
I am never destroying the objects and I use reliable sequenced for my channel 0 so I don't see any reason why the target would not be found.
Here is my NetworkManager, my player prefab and the prefab for the object I am spawning:
Here is the code for the player:
public class SimplePlayer : NetworkBehaviour {
[SerializeField]
private NetworkIdentity _Identity;
[SerializeField]
private GameObject _Spawnable;
private void Start () {
if(_Identity.isLocalPlayer) {
CmdSpawn();
}
}
[Command]
private void CmdSpawn() {
var instance = Instantiate(_Spawnable);
NetworkServer.Spawn(instance);
}
}
And here is the code for the spawnable (it's only to have it moving):
public class SimpleMove : NetworkBehaviour {
private int multiplier = 1;
[ServerCallback]
private void Update () {
transform.position += multiplier * Vector3.up * Time.deltaTime * 3F;
if(transform.position.y > 3F)
multiplier = -1;
else if(transform.position.y < -3F)
multiplier = 1;
}
}
Is there something I am doing wrong? What am I missing? I read the doc about object spawning on Unity's website and I can't figure out what's wrong.
Thanks for your help!
I just found the problem. It seems I misunderstood the Server Only checkbox from the NetworkIdentity component. It actually means that it exists only on the server while I thought it meant it was controlled by the server.