|
After calling DontDestroyOnLoad on a game object that we want to pass between levels. Eventually we want to finally destroy it... say to reset the game to the initial state. Is there a way of undoing DontDestroyOnLoad without immediately destroying the object.. the command: Destroy(this.gameObject); will cause issues if other game objects that are in the same scene still depend on it. I just want it to get destroyed with all of the other game objects on the next level load.
(comments are locked)
|
|
No way to do it automagically no best way i can think of doing it is this:
that way you get your object destroyed before the first update in the new level Due to event execution ordering the above code was giving me runtime threading errors. I think the issue is that Destroy does not take action immediately and there is some overlap between its call, other event phases of the event loop, and its action. The run-time error goes away if I do replace Destroy with DestroyImmediate. (however there could be still un-reported errors)... thats it for now.
May 27 '10 at 05:51 PM
badneighbor
(comments are locked)
|
|
If you're destroying it and it's then being recreated for the level you've just loaded to (I'm assuming this from your comment about destroy and destroyimmediate) why don't you make a reset method for the object that puts it back in its initial state. That way you could just replace the destruction with a reset and carry on.
(comments are locked)
|

I to wish you could write something like DontDestroyOnLoad (go, true); The boolean would say wether it is destroyed or not on load.