Search Unity

Question can open or close Subscene by script?

Discussion in 'Entity Component System' started by seojihyuk, Jul 30, 2022.

  1. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    Hello, I'm using subscene and I want to open subscene by script.
    Because I found when I built project by new build configuration, it seems not opened the subscene even I opened in editor before I build.
    So I've experimented in editor by using LoadSceneAsync method.
    It looks like the subscene loaded well, but still in closed.
    I wonder if there is a way to open subscene by script.
    Thanks for reading.
    By the way I'm using Entites 0.51 package and unity 2020 LTS(3.37f1).
     
  2. DatCong

    DatCong

    Joined:
    Nov 5, 2020
    Posts:
    87
    ofcourse u can do that.
    1. Get SceneSystem
    2. SceneSystem.LoadScene( guid ) (u can get guid on go's subscene)
     
  3. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    Does this mean LoadSceneAsync? cause I've got this error.
    • error CS1061: 'SceneSystem' does not contain a definition for 'LoadScene' and no accessible extension method 'LoadScene' accepting a first argument of type 'SceneSystem' could be found (are you missing a using directive or an assembly reference?)
    And I've already tried LoadSceneAsync which just load not open the subscene.
     
    DatCong likes this.
  4. DatCong

    DatCong

    Joined:
    Nov 5, 2020
    Posts:
    87
    my fault,that is LoadSceneAsync, show me your code.
     
  5. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    Brefly, this is my code.

    Code (CSharp):
    1. public SubScene prefabScene;
    2.  
    3. private void Start()
    4. {
    5.   sceneSystem = entityManager.World.GetOrCreateSystem<SceneSystem>();
    6.   sceneSystem.LoadSceneAsync(prefabScene.SceneGUID);
    7. }
    8.  
    and this is what happening on my editor.
    unity_before_start.png unity_after_start.png
     
  6. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Is it possible to detect when a subscene is closed? I don't see an event, and nearly all the functions in SubScene.cs are private by default so I can't inherit SubScene and override a function such as AddSceneEntities() or OnValidate() without changing the source code of SubScene.cs itself.