I’m trying to delete projectiles in my multiplayer game that are no longer visible to reduce lag by tagging them and looping through objects with that tag, then destroying them if the position is under -75. It seems to work, but keeps giving me errors like Couldn't destroy object because the associate network view was not found UnityEngine.Network:Destroy(GameObject)
and View ID AllocatedID: 4 not found during lookup. Strange behaviour may occur UnityEngine.Network:Destroy(GameObject)
. What do these errors mean, and how can I fix them? Here’s my code:
void Update(){ GameObject[] discs; discs = GameObject.FindGameObjectsWithTag("Projectile"); foreach(GameObject disc in discs){ if(disc.transform.position.y < -75){ Network.Destroy(disc); } } }
these errors mean 1 of a few things:
- the object was destroyed on one system, and then the destroy command was sent to the other systems (this will happen if the Network.Destroy() call is placed inside of a method that is being called RPC because Network.Destroy is also RPC which can result in a sudo cascade effect.
- the same NetowkId was allocated for more then 1 thing (look into how you allocate them, and the possible values.
- when you went to destroy the object you did not clear the RPC calls first.