Search Unity

Loading scene and not destroying

Discussion in 'General Discussion' started by janlovsin, Jun 16, 2018.

  1. janlovsin

    janlovsin

    Joined:
    Jun 7, 2018
    Posts:
    12
    I used to program using libraries where I managed all myself -> When I loaded the game there was a MySceneManager that loaded all the assets, resources and scenes and kept references to them, so they didn't get detroyed.

    How do we handle these things in Unity (because creating each scene and intialising its objects is really costly)?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    If you want to keep GameObject's alive, even when loading another scene, you can mark them with Object.DontDestroyOnLoad(gameObject). This works on root-GameObject's only.

    If you want specific assets to stay in memory, you can mark them via HideFlags.