How can I get the SceneInstance

I have two scenes, dungeon and battle, when an encounter happens in the dungeon I disable arbitrary things there and load battle scene sync using the LoadSceneAsync API, and after this, I pass the SceneInstance thought context, so later on I can unload the battle scene using this cached SceneInstance, something like

private IEnumerator Encounter()
{
    // Fade in
    yield return fadeBackground.FadeInRoutine();
  
    // Hide/Disable dungeon things
    OnChangeToBattleScene?.Invoke();
  
    // Load battle scene
    var sceneChangeHandle = battleScene.LoadSceneAsync(LoadSceneMode.Additive);
    yield return sceneChangeHandle;

    ctx.battleScene = sceneChangeHandle.Result;
  
    // Trigger event
    GameEvents.Battle.RaiseSetupBattle(ctx);
}

BUT now I have a rigid sequence of actions - dungeon → battle → dungeon - which is fine for a release version, but during dev, I want to be able to change between scenes in any arbitrary sequence, but I cant find a way to create a SceneInstance that is required for UnloadSceneAsync. Any help is welcome

I don’t think you can, as, if you’ve entered the scene via play mode, the scene hasn’t been loaded by addressables. You’ll just need to code in editor fallbacks to unload the scene via traditional means if its the scene you’ve entered via play mode.

1 Like