Forum rules - please read before posting.

Adding a SubScene asynchronously?

Hello. What I want to achieve is a seamless transition between scenes. What I was planning on doing was load the next scene asynchronously and additively so the player can keep playing while it loads. Then I would move the new scene to the appropriate location and once the player has completely "entered" the new scene, I would unload the previous scene. I thought of using AddSubScene(), which adds the new scene additively but not asynchronously, which causes my game to freeze for a few seconds while it loads. Is there a way to use AddSubScene() asynchronously? Or is there a better way to achieve what I want?

Comments

  • If you opt to use Unity's Addressable system for scene-switching, added scenes will be loaded asynchronously:

    1. Back up the project
    2. Import Unity's Addressable package from the Package Manager
    3. Add "AddressableIsPresent" to the Player setting's "Scripting Define Symbols"
    4. In the Settings Manager, set Reference scenes by to Name
    5. Check Load scenes from Addressables?
    6. Remove the scene from your Build Settings, and mark it as Addressable with a Key that matches its filename.
  • I was reading through the scripts and found that these lines are commented in the SceneInfo script:

    So even if I Add the subscene, it would still not be loaded asynchronously. So should I not use AddSubScene()? What should I use? I'm using AC version 1.74.2

  • If I remove the comments, I get an error with handle.WaitForCompletion(). It says it can't be found.

  • Another thing. How can I deactivate the player from the previous scene and set the one found on the new scene as the player?

  • You will need to backup and update your AC version to make use of the uncommented code.

    How can I deactivate the player from the previous scene and set the one found on the new scene as the player?

    It depends on whether or not you have "Player switching" enabled in the Settings Manager.

    If not, placing a local Player character inside the new scene file will override your default for the duration of that scene.

    If so, set the new Player's position to the new scene using the Player: Teleport inactive Action (or setting their default data as such) and switch to them using Player: Switch. AC will handle the scene-switching automatically.

  • I tried changing this line in SceneInfo's Open() to LoadSceneAsync. Are there any downsides to this?

    If not, placing a local Player character inside the new scene file will override your default for the duration of that scene.<

    I don't have it enabled. I have every scene with its own player. But the player is different in every scene because I need them to have different components and animators assigned to them.

    When I Add the subscene, the player from the new scene is Turned Off and the AC Status box shows the active player is the one from the previous scene. If I turn off or delete the previous player, and then turn on the new one, the Status Box doesn't show any active player.

    Using Player: Switching didn't seem viable because it instantiates the player prefab to the scene, rather than using the one I have placed in the scene. I have some scripts and components in the scene referencing the player gameObject in the scene, so when AC instantiates the new one, those references are lost.

  • I tried changing this line in SceneInfo's Open() to LoadSceneAsync. Are there any downsides to this?

    You might be OK. Check that switching between saves that have the scene open and not work, though.

    When I Add the subscene, the player from the new scene is Turned Off and the AC Status box shows the active player is the one from the previous scene.

    The Player will only be overridden when switching scenes - sub-scenes won't count.

    You can try setting the Player manually with:

    AC.KickStarter.player = myNewPlayer;
    

    However, this change will not be reflected in save-game files, so you'd need to call this after loading a save file as well.

    I have some scripts and components in the scene referencing the player gameObject in the scene, so when AC instantiates the new one, those references are lost.

    A custom script ought to be able to re-assign such references upon spawning the Player.

  • That worked!! thanks!!

    I tried changing this line in SceneInfo's Open() to LoadSceneAsync.

    I tried using UnityEngine.SceneManagement.SceneManager.LoadSceneAsync() directly on my script without using AC's AddSubScene(). It seems the scene got added as SubScene anyway. Can I do this without breaking anything? This way I can avoid modifying AC's scripts.

  • It should do - but again, double-check that saves are working.

  • After loading a scene like this, my conversation menu breaks and I can no longer navigate it. Could it be something to do with this?

  • Revert back and load in the normal way - does it work again?

    What exactly is the issue with the menu - do the options not show, or is it not interactive? If the latter, what is the Menu's Source and how is it intended to be navigated? With the mouse, or with direct input? The more details you can share, the better I can understand the situation.

  • The menu shows correctly but is not interactable. It's a Unity UI menu. I think it's because my InputManager prefab is being deleted with the old scene. So the Event System disappears. I tried having it not destroy on load. That seemed to work in the editor but apparently it doesn't on builds. I also have some AC menus that appear with an Input key. Those stop showing up at all after I load the new scene.

  • What is this InputManager prefab you're using? It's not a part of AC.

    You can assign a custom EventSystem prefab in the Menu Manager - AC will spawn this into the scene when needed. Alternatively, place a copy of any necessary prefabs into the scene files manually - avoiding a need to have the survive scene changes.

  • That's what I meant. The EventSystem prefab. It's called InputManager so maybe I got confused.

  • If you're opening a scene manually, without running it through AC, then AC's startup process may not kick in properly.

    You can place an Event System object manually in the scene file, but you may encounter other issues elsewhere.

    The latest release, I should mention, has the ability for sub-scenes to be loaded asynchronously.

  • What about the manus that aren't working? I have some menus to appear with an input key. But they stop appearing as soon as I remove the previous scene. Is there some line of code I should run to "reset" the menus or something?

  • edited February 10

    You can try calling the RebuildMenus function, but I'd recommend using AC's own scene-switching system to avoid these (and potentially other) issues:

    AC.KickStarter.playerMenus.RebuildMenus ();
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.