Dillon
1
So I have a server only object that spawns objects periodically using Network.Instantiate and when a client connects at the start things are fine (all synched up), but then if that client disconnects and reconnects there are extra copies of the spawned object (Not necessarily in the same place, so it might not be an actual clone) and I don’t really know why.
if(RandomType == 0)
{
clone = Network.Instantiate (FactChecker, Vector3((transform.position.x)+ Random.Range(-RandAmountX, RandAmountX), -14, transform.position.z), Quaternion.identity, 1);
Destroy (clone, 65);
}
The destroy is just a safety measure, in case it gets lost on it’s way to be destroyed, do I have to do a RPC call with Network.Destroy in it? I’m not totally sure that’s what causing my problems but I’m sure it isn’t helping. In other places when the object gets destroyed by say, getting shot and dying, I just do a Network.Destroy without the buffered RPC call, is that okay?
Network.Instantiate automatically buffers the instantiation- which means that if you reconnect, it resends all of the Instantiate commands. If you need to set it up so that it only ever happens once, use a manual RPC that works something like this-
[RPC]
void SpawnThing(NetworkViewID newID)
{
GameObject newThing = Instantiate(FactChecker,
Vector3(Vector3((transform.position.x) +
Random.Range(-RandAmountX, RandAmountX), -14, transform.position.z),
Quaternion.identity) as GameObject;
newThing.networkView.viewID = newID;
}
And then when you actually use it, call it like this
networkView.RPC("SpawnThing", RPCMode.All, Network.AllocateViewID);
This maintains synchronisation, but does not automatically buffer the object the way Network.Instantiate does.
Be careful, though that these objects do not carry important game logic- if the player disconnects and then reconnects they will lose all of the network views in question. You will need to have some other code that keeps track of things that need to be synchronised, and which resends all the relevant synchronisation information through some object which is guaranteed to be synchronised.