Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    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:
    639
    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:
    639
    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?