Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by Orion 1 · Jun 28, 2010 at 03:31 PM · errorobjectscenecleanupondisable

"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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-3333 (yahoo) · Jun 29, 2010 at 05:58 PM 0
Share

Anyone willing to add to describe how this error happens? I've tried removing calls to the destroy method, with no luck.

avatar image Orion 1 · Jul 01, 2010 at 02:35 PM 0
Share

Hm. As my solution doesn't seem to do it for you, I'm not gonna mark it as the answer.

8 Replies

· Add your reply
  • Sort: 
avatar image
5
Best 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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

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().

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image trialforce · Nov 19, 2016 at 02:16 PM 0
Share

It solves my Scene$$anonymous$$anager.LoadScene(sceneName) problem. Thanks!

avatar image
1

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();
   }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges