Scene Portals with asynchronous scene transitions

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Geri860
Posts: 8
Joined: Fri Sep 10, 2021 9:00 am

Scene Portals with asynchronous scene transitions

Post by Geri860 »

Hi Toni,

Can you help me a little? Here is the scenerio:
I have a few smaller scenes, and I want to make it transition faster between them.
Essentially, the way I want to make it work is to tell a scene portal, that load the destination scene which is typed in the editor additive, and only load that scene when I enter the portal. I know how to make an async loading work, but not with the quest machine's scene portals.
I won't even need the scene transition animation, just to make it more snappier.

Is there a way to do that?
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scene Portals with asynchronous scene transitions

Post by Tony Li »

Hi,

You essentially want to stream parts of the world in and out as the player moves around? If so, you can make a subclass of ScenePortal and override the UsePortal method. Example:

Code: Select all

public override void UsePortal()
{
    if (isLoadingScene) return;
    isLoadingScene = true;
    onUsePortal.Invoke();
    //-- Don't use this: LoadScene();
    SaveSystem.sceneLoaded += OnSceneLoaded;
    SaveSystem.LoadAdditiveScene(destinationSceneName);
}

private void OnSceneLoaded(string sceneName, int sceneIndex)
{
    isLoadingScene = false;
    SaveSystem.sceneLoaded -= OnSceneLoaded;
}
You'll probably also want a script that unloads an additively-loaded scene when the player gets to a position that's far away from the scene. In that script, use SaveSystem.UnloadAdditiveScene().

SaveSystem.LoadAdditiveScene and UnloadAdditiveScene are like Unity's additive SceneManager.LoadScene/UnloadScene methods, except they also maintain save data properly.

Alternatives are to use the free but basic Scene Streamer asset, or the more advanced but paid SECTR Stream or World Streamer. If you use any of these alternatives, you'll need to write some code that tells the SaveSystem to record outgoing scenes' savers, and to apply saver data to savers in newly-loaded scenes.
Geri860
Posts: 8
Joined: Fri Sep 10, 2021 9:00 am

Re: Scene Portals with asynchronous scene transitions

Post by Geri860 »

Hey,

Thank you Tony, I've made it work!
User avatar
Tony Li
Posts: 21926
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scene Portals with asynchronous scene transitions

Post by Tony Li »

Happy to help! I'm glad you made it work. :-)
Post Reply