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. Dismiss Notice

Question Some Subscenes Not Loading

Discussion in 'Entity Component System' started by charleshendry, Feb 10, 2023.

  1. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    95
    I have a scene with several subscenes. They all have identical settings (autoload and are closed).

    subscenes1.png


    But when I run the scene, some of them don't load.

    subscenes2.png

    I've cleared the Entity cache and tried reloading etc, but can't get them working.
     
  2. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    95
    Ok sorry, it was because some code was trying to access the converted Entities, but they weren't available in time. Is there a way I can halt the code until all subscenes are loaded? Note that the same Entity types also exist in other subscenes, so using a
    RequireForUpdate<>
    won't work.
     
    apkdev likes this.
  3. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    263
    In my code I wait for subscenes to load like this (in a coroutine):

    Code (CSharp):
    1. foreach (var subscene in FindObjectsOfType<SubScene>())
    2. {
    3.     var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(LocalToWorld), typeof(SceneSection));
    4.     query.SetSharedComponentFilter(new SceneSection { SceneGUID = subscene.SceneGUID });
    5.     yield return new WaitWhile(() => query.IsEmpty);
    6. }
     
    charleshendry likes this.