Search Unity

AsyncOperation.allowSceneActivation

Discussion in 'Documentation' started by PeteD, Oct 3, 2014.

  1. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    When this is used for delaying the loading of a level the level progress will always stall at 90% and the isDone flag will remain false until allowSceneActivation is set back to true.

    The documentation for this flag is therefore incorrect as it states

    "Allow scenes to be activated as soon as it is ready."

    To check a level is ready you would use the isDone flag on the AsyncOperation object but, that will never be set to true until allowSceneActivation is set to true and progress is allowed to go to 100%.

    So it should state something along the lines of "If set to false will stalls scene loading progress at 90% and isDone flag will remain as false. This allows for manual control of the level completion process. Loading will only continue once the allowSceneActivation flag is set back to true."

    Either that or how the flag works (and has always worked as far as I remember) is a bug. Though it's worked this way since 4.01
     
  2. yoyo

    yoyo

    Joined:
    Apr 16, 2010
    Posts:
    112
    I tried to use allowSceneActivation to let me load a level using additive load of multiple scenes, but delay the activation until all the loads were complete. However it seems to be impossible to have more than one pending scene activation, so this doesn't work.

    All in all, allowSceneActivation seems poorly thought out and implemented. I'm giving up on it. Would like to hear from anyone who has better luck.
     
  3. PeteD

    PeteD

    Joined:
    Jul 30, 2013
    Posts:
    71
    Yes it's pretty vague how this is supposed to actually work. I've coded as it works now but, given that this needs changing at the unity end. I'm reluctant to spend any real time using it.
     
  4. Sycobob

    Sycobob

    Joined:
    Feb 1, 2013
    Posts:
    78
    I think this an issue with misunderstanding regarding how async level loading works, rather than a bug in the documentation or the engine. However, I absolutely agree the documentation is not clear enough. I learned the following by using it and observing the behavior, which isn't the best way to learn how a feature is intended to work.

    Async loading takes place in 2 steps, loading from disc and activating the scene. Loading from disc is truly asynchronous because it happens on another thread. Thus you can do work while this is going on. Activating the loaded scene (i.e. calling Awake on all your enabled Components, etc) is synchronous and thus locks up the main thread (your code). Setting allowSceneActivation to false stops the second step from taking place. The way Unity has chosen to implement it, progress will be at .9 when the first step finishes. The load operation isn't complete because you haven't activated the new scene, so it makes sense for isDone to be false and for progress to be < 1. I don't like the fact that this is represented using a 'magic number' rather than an appropriately named property that denotes the current step/state or something similar, but it is what it is.

    In our case, we leverage async loading to enabled us to use a loading screen without extending the load times. When it's time to move to a new scene we start an async load with allowSceneActivation set to false and we start fading in a loading screen at the same time. Once the loading screen is fully transitioned in and it's safe to activate the new scene without the user noticing the fact that the application will lock up for a few seconds we set allowSceneActivation to true.

    However, the bigger issue with async loading is that, in my experience, it's not very safe/stable. There are a fair number of ways to crash the engine when using async loading that don't occur when using sync loading. We've run into problems with loading a scene while timeScale is 0 and with enabling WheelColliders during scene activation. Until this is addressed head on, I don't find async loading to be worth using. (It helps that on modern HDDs, step 1 is quite fast, so you're probably not gaining a lot from async loading anyway. You can improve load times more by optimizing what goes on during scene activation).