I’m not sure if this is the place but since its not a problem I can see as far as my code goes, I have code structured like the following:
//_transform is a cache of transform made in Awake
void Update() {
...
if (!alive !dead)
{
_timer += Time.deltaTime;
if (_timer > deadTime)
{
Instantiate(explosionPrefab, _transform.position, _transform.rotation);
GameObject.Destroy(this.gameObject);
dead = true;
}
}
...
}
Once the GameObject.Destroy(this.gameObject); line runs unity crashes. :3 haaaalp
solved: im so silly I forgot that the camera had a script tracking the object, and when the object was destroyed the camera script was trying to access a null object, causing a cascade crash. ;3 fixed
I’ve always used just Destroy(gameObject) (rather than GameObject.Destroy(this.gameObject) ). It could be that that particular syntax has a bug (calling it from the static GameObject class rather than from the instance of a MonoBehaviour).
If that doesn’t make the difference - are you referring to the destroyed gameObject or any of its components later in that function? That could cause problems.