- Home /
"Some objects were not cleaned up when closing the scene"
I'm getting the following error:
Some objects were not cleaned up when closing the scene
Error in file ....\Runtime\Misc\SaveAndLoadHelper.cpp at line: 161
Now I don't think this message could be any less helpful. Unfortunately, no one else seems to have had this problem before. I'm unable to isolate the error, as it's a very complex scene. Does someone know what could cause an object to not be cleaned up?
Anyone willing to add to describe how this error happens? I've tried removing calls to the destroy method, with no luck.
Hm. As my solution doesn't seem to do it for you, I'm not gonna mark it as the answer.
Answer by Digitalos · Jul 21, 2010 at 01:35 PM
In order to resolve this error message, make sure to check if the script is enabled, for example:
public void OnDisable(){
if(this.enabled){
// Do stuff.
}
}
This will ensure it only runs OnDisable when the object is destroyed which is what you wanted in your behaviour.
Answer by Schuberbia · Nov 19, 2011 at 12:02 AM
I ran into this same error and figured out my issue today. It turns out my problem was I was in instantiating a death effect in OnDestroy(). I am presuming this was putting the new object into the scene graph after the graph was copied to a temporary variable to be iterated over for destroying things, or possibly screwing with an iterator being used to traverse the graph or something. In any case, the object wasn't getting cleaned up.
So, the short version - don't instantiate stuff in OnDestroy().
Answer by Orion 1 · Jun 28, 2010 at 03:48 PM
Hum. In a silly attempt to clean up my objects, I had added this code to a sometimes used object:
public void OnDisable()
{
if (renderer.material != null)
{
Destroy(renderer.material);
}
}
Removing this function fixed the problem. Turns out I shouldn't meddle with these things.
It solves my Scene$$anonymous$$anager.LoadScene(sceneName) problem. Thanks!
Answer by ProjSHiNKiROU · Dec 13, 2011 at 03:05 AM
These answers did not solve the problem, but instead, I eliminated the OnDestroy
call because my code is simple enough.
void OnCollisionEnter(Collision collision) {
Destroy(gameObject);
}
void OnDestroy() {
Instantiate();
}
becomes
void OnCollisionEnter(Collision collision) {
addExplosion(); //
Destroy(gameObject);
}
void addExplosion() { //
Instantiate();
}
Answer by Antony-Blackett · May 25, 2011 at 10:42 AM
This can happen when you make a MonoBehaviour that has a name that does not match its file name. Normally Unity will warn when you try and add the component to a GameObject via the inspector however it will not warn you when you use AddComponent() at runtime.
Your answer
Follow this Question
Related Questions
DontDestroyOnLoad with object on another scene 2 Answers
Operator '+' cannot be used 1 Answer
Go To new Scene Button! 1 Answer
Error: NpRigidDynamic::isSleeping: Body must be in a scene. 1 Answer
Having problems destroying an Object 2 Answers