- Home /
Why when destroying objects when quitting the game it's destroying the objects only in hierarchy ?
The objects still exist in the game view and scene view they are destroyed only from the hierarchy. How can i destroy them also from the scene/game view ?
public void DestroyNodes()
{
GameObject[] nodes = UnityEngine.GameObject.FindGameObjectsWithTag("Node");
if (nodes.Length == 0)
{
//Debug.Log("No nodes to destroy found");
}
else
{
for (int i = 0; i < nodes.Length; i++)
{
DestroyImmediate(nodes[i]);
}
}
}
And in another script:
private void OnApplicationQuit()
{
levelGenerator.DestroyNodes();
}
If i try to make only Destroy and not DestroyImmediate i'm getting exception:
Destroy may not be called from edit mode! Use DestroyImmediate instead.
What you say doesn't make sense. Every gameobject visible in the scene is listed in the hierarchy. Click on one in the scene view and it will highlight in the hierarchy. For the problem with destroy, I think destroy is delayed to a point in OnApplicationQuit when the game has quit and you're back in edit mode again, that's for the error.
The reason for the objects you stay is, if they existed prior playing, that under normal circumstances, everything gets reset after exiting play mode. Except for scriptable objects.