- Home /
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 :
http://answers.unity3d.com/questions/169656/instantiate-ondestroy.html
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!
Answer by meat5000 · Jul 20, 2015 at 03:37 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113047im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error NullReferenceException: Object reference not set to an instance of an object 1 Answer
Getting ArgumentOutOfRangeException on array c# 1 Answer
Need help calling a script to another keep getting errors 1 Answer
2D platformer- getting errors I don't understand (c#) 1 Answer