- Home /
Can you undo "dont destroy on load"?
I have objects that need to be kept between multiple scenes, so I use Dont Destroy On Load. However, I need to have the option to cancel this and allow these objects to be destroyed on load at a later point. Is there a way to cancel or undo the Dont Destroy On Load function?
Use a static class otherwise. Store all the info you need and retrieve them when you need them.
Answer by dorpeleg · Aug 26, 2013 at 10:12 AM
Not sure if it will work, but you can try this:
Put the DontDestroyOnLoad under an if statement.
something like:
if('condition here') {
DontDestroyOnLoad(gameObject);
}
Then, just make sure the if is true while you don't want to destroy the object and false when you do.
It's not that simple, once you call DontDestroyOnLoad, the object will never be destroyed by scene loads anymore, never, the only way to destroy that specific object is to explicit call Destroy(object).