Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Scripting SceneManager.UnloadScene destroys everything?

Discussion in '5.3 Beta' started by mihakinova, Nov 16, 2015.

  1. mihakinova

    mihakinova

    Joined:
    Jan 6, 2015
    Posts:
    85
    So here is my scenario. I load a scene with SceneManager.LoadSceneAsync, and mark some objects with DontDestroyOnLoad. Then, at some point in the game, I unload the current scene with SceneManager.UnloadScene.

    The scene AND all the objects marked DontDestroyOnLoad are destroyed. I would not expect this behaviour. Is it possibly a bug or is UnloadScene expected to destroy everything? If so, is there a way to unload a scene while keeping the DontDestroyOnLoad objects intact?
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    433
    Hi,

    From what you describe it sounds like a bug. Can you please file a bug report and attach a project that reproduces the issue.
     
  3. mihakinova

    mihakinova

    Joined:
    Jan 6, 2015
    Posts:
    85
    I could not reproduce the bug anymore, however, a related bug occured, and I filed it under case #745325
     
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    433
    Hi

    We found and a fixed a bug. If you at runtime in a standalone player loaded a scene and marked some of the loaded objects with DontDestroyOnLoad, then unloading the scene would destroy these objects. The bug does not reproduce in the editor.
     
  5. mihakinova

    mihakinova

    Joined:
    Jan 6, 2015
    Posts:
    85
    Hi, I got the bug again today and it took me a while to remember this thread. It's true, when unloading a scene on a device (iPad in my case) Unload destroys everything.

    Is it known when this bugfix will be released?