Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LoadLevelAdditiveAsync hiccups

Discussion in 'Editor & General Support' started by jimmikaelkael, Oct 6, 2015.

  1. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Hi,

    I'm currently converting a big open world scene into smaller chunks so it can be streamed at runtime with LoadLevelAdditiveAsync.

    This works as I expected, however I get a very small hiccup (less than one second) in the standalone build the FIRST time each additive scene is loaded. After it has been loaded once, no more hiccups. I can even restart the game completely and no hiccup.

    This happen when I'm running the game the first time after I started the computer.

    What it could be ?

    Is it a matter of additive scene lightmap ? It seems it's not unloading when you unload the additive scene, as you can read on this thread:
    http://forum.unity3d.com/threads/un...g-loadleveladditiveasync.354391/#post-2327145

    Maybe a matter of shader loading when I open scenes additively the 1st time ?
     
  2. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    After some tests, shaders preloading doesn't change anything...
     
  3. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    I'm curious about this, too. For me, this also happens when loading small scenes, not just when loading large amounts of data.
    Unfortunately, I haven't found a perfect solution yet.

    But this is how I managed to reduce the problem with LoadLevelAsync:
    Code (CSharp):
    1. AsyncOperation async = LoadLevelAsync("SomeLevel");
    2. async.allowSceneActivation = false;
    3. while (async.progress < 0.9) {yield return null;}
    4. async.allowSceneActivation = true;
    5. LoadLevel("SomeLevel");
    Maybe it works for LoadLevelAdditiveAsync, too?
    Of course, you wouldn't use LoadLevel("SomeLevel") then, though, but maybe something like this?:
    Code (CSharp):
    1. AsyncOperation async = LoadLevelAdditiveAsync("SomeLevel");
    2. async.allowSceneActivation = false;
    3. while (async.progress < 0.9) {yield return null;}
    4. async.allowSceneActivation = true;
    5. LoadLevelAdditiveAsync("SomeLevel");
     
    Last edited: Oct 6, 2015
  4. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    @Shushustorm On my side these small hiccups only appears when each scene is loaded additively on first time after a fresh computer start. After that, I do no longer have hiccups, even if I restart the application completely. As a workaround I could load and unload each scene during main level initialization.

    I don't understand why you are calling LoadLevelAdditive twice... Something like that should be sufficient, and make sure to start it with a coroutine:
    Code (csharp):
    1.  
    2. public void LoadLevel () {
    3.     StartCoroutine (LoadLevelCoroutine ());
    4. }
    5.  
    6. IEnumerator LoadLevelCoroutine () {
    7.     yield return Application.LoadLevelAdditiveAsync (levelName);
    8. }
    9.  
     
    Shushustorm likes this.
  5. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Code (CSharp):
    1. AsyncOperation async = LoadLevelAsync("SomeLevel");
    2. async.allowSceneActivation = false;
    3. while (async.progress < 0.9) {yield return null;}
    4. async.allowSceneActivation = true;
    5. LoadLevel("SomeLevel");
    I call LoadLevel() after async.allowSceneActivation = true, because I haven't been able to load a scene with just allowing scene activation again. It seems you actually have to load the level afterwards "again" (just with the difference that 90% of the content is already loaded).
    I don't know how that works with Additive, though. It may as well mess things up and add a scene multiple times for whatever reason.
    Oh and there is another thing you can do that may be working for you: Setting the priority to BelowNormal or to Low:
    Code (CSharp):
    1. AsyncOperation async = LoadLevelAsync("SomeLevel");
    2. async.allowSceneActivation = false;
    3. async.priority = ThreadPriority.Low;
    4. while (async.progress < 0.9) {yield return null;}
    5. async.allowSceneActivation = true;
    6. LoadLevel("SomeLevel");
    Then, the procedure may take a little longer, but the impact on performance is smaller.

    Also, I really don't know why this only occurs once after restarting the computer.
    For me, this happens all the time. So maybe there is another specific solution for your problem.
     
    Last edited: Oct 7, 2015
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    @Shushustorm Thank you for the suggestion: I tried with a low AsyncOperation.priority but it didn't changed anything... I think it's for use when you spawn several AsyncOperation concurrently.

    However for now I stick with the workaround I mentionned above which is to use an initialization stage when loading level where I load and unload every additive scene (kind of stupid but works).
     
    Shushustorm likes this.