Search Unity

Wait for SubScene to finish loading via LoadSceneAsync

Discussion in 'Entity Component System' started by nicolasgramlich, May 19, 2020.

  1. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Hey everyone,

    so one annoying thing I run into while slowly switching more and more things to subscenes is that when I switch scenes via
    UnityEngine.SceneManagement.SceneManager.LoadSceneAsync
    is that it doesn't wait for subscenes to be loaded as well.

    I.e. it looks pretty funky if you have all the environment in a subscene and some characters in the root scene, the characters will float in the void for a few milliseconds before the subscene is done loading.

    I'm wondering what the recommended approach for this is beyond just waiting a few extra frames :confused:?

    I was imagining
    LoadSceneAsync
    would take some parameter so one can decide to have subscenes loaded synchronously as well before returning.

    Regards,
    Nicolas
     
    lclemens likes this.
  2. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    352
    How you solved it? I have seen in SceneSystem.cs that LoadSceneAsync returns "An entity representing the loading state of the scene". So we could write little simple async method that will return yield until we can ensure that scene is loaded. But what component is representing subscene loading state on that entity? I see no such component being added during method.

    UPD: there is method SceneSystem.IsLoaded(Entity) which using mentioned entity to return loading state
     
    Last edited: Jul 24, 2021