- Home /
Destroy GameObject won't destroy
Hi, I have a prefab instance which I am instantiating and destroying thus:
public var block : GameObject = null;
block = Instantiate(blockPrefab, originVector, Quaternion.identity);
Destroy(block);
The block is disappearing on Destroy. However the null comparison is not executing and I can still query transform info, attach textures etc!:
if (block == null) {//not happening}, block.transform.position, block.renderer.material.mainTexture = Resources.Load("pink"); (the last 2 excerpts do not throw a NullPointerException)
If I remove the Destroy call, the object is there and rendered pink. I read Destroy nullifies a GameObject, or at least this (block == null) would return true. But it's not. Any ideas pls?
Thanks
Answer by whydoidoit · Jul 28, 2012 at 07:49 AM
Destroy destroys the game object after the current Update loop completes (to stop lots of errors). At that moment the object reference will start returning null. You can call DestroyImmediate if you want it to happen at that instant and then the reference will immediately start returning null.