Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to load a SubScene at runtime?

Discussion in 'Project Tiny' started by BlaiseRoth, Oct 5, 2020.

  1. BlaiseRoth

    BlaiseRoth

    Joined:
    Oct 11, 2016
    Posts:
    8
    I have 50+ SubScenes for my game which are all different levels. I want to be able to swap them in and out by unloading the current level SubScene, and then loading in the new one.

    I understand there's SceneService.LoadSceneAsync, which takes a SceneReference as a parameter, but I'm unsure how to even get a SceneReference to one of my many level scenes. I'm thinking I would like to have some authoring component that I can serialize a list of all my SceneAssets, and then have them accessible as SceneReferences after conversion, or something like that.

    Does anyone have any example code for this kind of thing? I'm more concerned about the authoring side of things, but examples for just swapping in and out SubScenes at runtime would be useful. Or maybe I'm doing it wrong and SubScenes weren't meant to be used like this... any help would be appreciated.
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Hi,
    There are some limitations in the current version of tiny in terms of tagging and converting subscenes.
    We will have a better scene management system in the upcoming tiny release (scheduled later this month)
    and with that, you can tag a subscene with a component and you can use that component to load the scene.
     
    V_i_T likes this.
  3. BlaiseRoth

    BlaiseRoth

    Joined:
    Oct 11, 2016
    Posts:
    8
    Now that Project Tiny 0.31 is out, could I get an updated answer to this question? It's still unclear exactly how to load an unload scenes at runtime, especially with the fact that I have 50+ scenes, but I want to be able to swap between them.
     
  4. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    319
    Chek tiny racing sample
    We have added a new scene workflow
     
    elJoel likes this.
  5. elJoel

    elJoel

    Joined:
    Sep 7, 2016
    Posts:
    125
    Here's the relevant code:
    Code (CSharp):
    1.  
    2.  
    3. protected override void OnUpdate()
    4. var sceneSystem = World.GetExistingSystem<SceneSystem>();
    5.  
    6. ...
    7. var endingSceneEntity = GetSingletonEntity<EndingScene>();
    8.                 var endingScene = EntityManager.GetComponentData<SceneReference>(endingSceneEntity);
    9.                 sceneSystem.LoadSceneAsync(endingScene.SceneGUID, new SceneSystem.LoadParameters() { AutoLoad = true });
    10. ...
    11. sceneSystem.UnloadScene(endingSceneEntity);
    12. var endingSceneEntity = GetSingletonEntity<EndingScene>()
    13. }
    14.