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?
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().
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.
I hope this might be helpful. I just found and fixed this same symptom with the unhelpful “Some objects were not cleaned up when closing the scene” message. It dogged me for hours, as there was no help online that addressed my problem. I recently installed and am using EZGUI and wondered if it might be the source of my problem. I found that after binary search debugging, disabling gameobjects in my scene, I narrowed the problem to an object with two UIButton components. It would not be fair to blame EZGUI for this bug per se, but clearly there is a problem when two or more components occupy the same object, which could be said of many other component combinations.
That’s how we’ve worked it out in RageSpline. One line of code really Apparently we weren’t succeeding before because we were assigning the mesh data to a variable before calling DestroyImmediate on it (typical coder “make it legible” stuff) but that was leaving a reference in memory even after using the command. Doh. That’s with 3.5.3 btw.
public void OnDestroy () { DestroyImmediate(GetComponent().sharedMesh); }
I personally use OnBecameInvisible, though not all scenarios allow this.
Anyway, i think Unity really needs to add a new MonoBehavior like “OnDestroyRuntime” or something.