Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Persistent Level gameObjects

Discussion in 'General Discussion' started by SamohtVII, Oct 12, 2018.

  1. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    90
    Does Unity have anything in place where if I have a large scene with x amount of objects, then load a new scene with the same objects (But arranged differently) it will load quicker?

    Or does it just dump everything and rebuild the new level from scratch?
     
  2. hjohnsen

    hjohnsen

    Joined:
    Feb 4, 2018
    Posts:
    33
    Interesting question, I don't know if anybody already tried to benchmark Unity scene loading.
    If you want to handle it by yourself then you can probably set the 'don't destroy' flag before the new scene loading and then place the persistent objects at their new location.
    hj.
     
  3. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    196
    It just loads in the new level from scratch as Unity has no way of knowing if those references are to the exact same object between scenes, as scenes store references to each gameobject individually. If you want persistence then you'd have to dynamically load. Achieving what you want would be pretty simple. Essentially you'd just need to set them not to destroy on load, and have an array of the positions that you want them set to, and on load set them to the appropriate position.

    That's the easiest way I can think of at least. It's obviously going to load things differently between scenes because scenes each have their own references to gameobjects.
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,298
    Another option is to use additive scene loading, and multiscene setup, to avoid neccessary loading / unloading.
     
    Kiwasi likes this.
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,868
    Well, I think there is a misconception here.

    If you're asking that does unity reload all the assets between scenes, the answer is: no.
    Asset load is not dependent on the scene load other than the fact that unity is loading the assets which is not loaded already.
    So in a sense, unity does what you're asking in some way.

    If you have a finite set of assets which is used in the scenes, than unity will never unload the assets themselves, it will 'rearrange' them to cover the new scene. The thing which will be loaded is the scene asset.

    https://docs.unity3d.com/ScriptReference/Resources.UnloadUnusedAssets.html
    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.UnloadScene.html
    At least this is my interpretation what's happening.
     
    Kiwasi and Joe-Censored like this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,203
    That's half the story. That covers assets like sound tracks, models or prefabs.

    But the actual scene GameObjects get removed and new ones created in single scene loading. Which can take a non trivial amount of loading time if you have heavy scripts involved.

    You can get around this with additive scene loading or object pooling as appropriate for you game. If it needs it, many games don't.
     
    Lurking-Ninja likes this.
  7. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,868
    I was concentrating on the loading/unloading, but yeah, you're right, of course.
     
    Kiwasi likes this.