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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

How to NOT reset current scene while loading another?

Discussion in 'Scripting' started by saifshk17, Oct 15, 2018.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    485
    Hello all,

    How to not reset the current scene while the system loads to another scene? As in I would like to save the scene state when the user is currently in another scene and then come back to the previous scene to the last state.

    Thanks
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    I don't think there's a built-in way to do that (unless you count "loading scenes additively so that the old scene is never unloaded at all").

    Saving absolutely everything in a scene is (typically) a lot of data, most of which you (probably) don't need, because a lot of stuff stays the same or only changes in a few ways that you care about.

    Usually you should identify just a few key things that you care about and only save those, writing some custom code that can check the current values before unloading and then set things up appropriately after you load again.

    Depending on how much you need to save, and how long you want to save it, you might want to serialize the data and put it in a file, in PlayerPrefs, or in some other long-term storage. But if you only need a relatively small amount of information, and only need it while the program is running, you can probably just hold it in memory using static variables or in a GameObject that you've set to DontDestroyOnLoad.
     
    Vestxer and saifshk17 like this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    If you're not super tight on memory, then just deactivate all the GameObjects in the old scene, load the new scene additively, and reactivate them when you return.
     
    Vestxer and saifshk17 like this.
  4. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    485
    I can do this, but the thing I am trying to pause are the particles. If I jump to another scene while deactivating these game objects, it would not be in pause state. Looking for some way to hide it while using additive loading.
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);

    This might do the trick.

    Also, Particles can be resimulated back to the state they were if you set a custom rnd seed for them and then use .Simulate() on the ParticleSystem.