OnDestroy() : Some objects were not cleaned up when closing the scene

So im trying Instantiate, when object is destroyed, but when exiting from game to editor caused “IsPlayingOrAllowExecuteInEditMode” , i found solution :

by using

private bool isQuitting = false;

 void OnApplicationQuit()
{
    isQuitting = true;
}
 
void OnDestroy()
{
    if (!isQuitting)
    {
       Instantiate(megaBomb,transform.position,Quaternion.Euler(-90,0,0));
    }
}

It works, BUT its called in new loaded scene Application.LoadLevel(“Level”);

Some objects were not cleaned up when closing the scene

So i have copy of this object in new scene. How can i fix this? Thanks!

I quite imagine that objects are destroyed before the application quits.

This simply means that at the point that OnDestroy() is called, isQuitting = false;.

It follows that your megaBomb is attempting to Instantiate and as a result the GameObject itself can not be destroyed. If that attempt is successful you also have another object that will have potentially missed the round of Destroy()s.

http://docs.unity3d.com/Manual/ExecutionOrder.html