Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by antx · Sep 14, 2012 at 04:52 PM · dontdestroyonloadundo

how to Undo DontDestroyOnLoad

Very obvious case:

  • Game starts,

  • Start screen Level is loaded and makes a GameObject undestroyable on Load Level,

  • another level is loaded and stores data in the GameObject, and another one and another one...

  • at some point the player clicks on the "reset" button (availabe in each level) to bring him back to the Start screen Level, where everything should be as it was right after the Game started.

Now, the logical thing would be to somehow undo the DontDestroyOnLoad state of that GameObject and then call Application.LoadLevel("Start_screen_level"); .

But I just can´t find a way to undo DontDestroyOnLoad. Is there really no way to do this? (It seems to be such a basic and logical thing to have.)

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 shaderop · Sep 14, 2012 at 05:04 PM 0
Share

Can't you just manually call `Destroy` on the object in question?

avatar image antx · Sep 14, 2012 at 11:57 PM 0
Share

Damn I knew this would come... I think this is a dirty solution. And yes I tried this but it did not work. Directly after the destroy() I could still read my data from the Object.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by shaderop · Sep 15, 2012 at 12:02 PM

As I understand it, `Destory` makes the object for deletion at the end of the current frame. But you can use `DestroyImmediate` if that is not acceptable.

Also, did you consider manually resetting the object state instead of destroying it and then recreating it on restart? As in set all its fields to defaults or null, zero any collections it has, etc? Could net you a slight performance boost this way.

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

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

10 People are following this question.

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

Related Questions

Undo DontDestroyOnLoad? 2 Answers

Preventing variable from resetting when level loads 1 Answer

reload level whilst saving certain objects, without dontdestroy() 2 Answers

Is OnLevelWasLoaded supposed to be called twice when using DontDestroyOnLoad? 3 Answers

DontDestroyOnLoad does not work after reload the scene? 1 Answer


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