I have a gameobject, when it collides with another gameobject it destroys itself and a clone takes it place of where it was destroyed. However, when it clones itself it causes Unity to crash. Any idea why this is?
void OnCollisionEnter(Collision hit)
{
if(hit.gameObject.tag == "Wall")
{
Destroy(gameObject);
GameObject clone = Instantiate(boltprefab, transform.position, transform.rotation) as GameObject;
clone.gameObject.tag = null; //prevents multiple clones
}
}
As a guess change line 7 to: clone.gameObject.tag = ""; I'm guessing that there is an attempt to access the tag somewhere else, and you are generating a null reference exception.
– robertbualright it doesn't crash anymore, but the changed caused it to become boltprefab(clone)(clone)(clone).....(clone) in the hierarchy , have a feeling it that's a bad thing, since it should be just "boltprefab(clone)" and will crash the more of those I have in the scene
– IAmJeff