Load additive scene with spawning

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hidingso
Posts: 26
Joined: Sat Sep 25, 2021 2:07 pm

Load additive scene with spawning

Post by hidingso »

Hello,

First, I love the asset. Whenever there is a feature I am looking for, this thing has it. I love it!

Is there a reason LoadAdditiveScene doesn't support player spawnpoint?

My "Start" scene contains just Main Menu and the basic Load game functionalities.

My main scene, "Persistent", contains the Player model, camera, global lightning, game managers, the usual. This scene is always there and everything is loaded additively.

Scenario #1: I have "Persistent" scene loaded and 1 additive scene, "City", loaded. I walk to a door which is a trigger for scene change to "House". I guess normally I could call "LoadScene("House", "SpawnInsideHouse"), but cannot because It would unload my other scenes. I call "LoadAdditiveScene("House").

I guess I have to relocate my player with my own script, which is no big deal, but made me wonder if I am missing something here?

Thanks in advance!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Load additive scene with spawning

Post by Tony Li »

Hi,

With SaveSystem.LoadAdditiveScene(), we don't know whether you're loading a new location for the player to be in (e.g., "House") or just streaming in more of the world for the player to continue moving through (in which case you don't want to move the player).

If you're additively loading "House", I recommend registering a method with SaveSystem.sceneLoaded. In this method, manually call the player's PositionSaver.ApplyData(). For example:

Code: Select all

SaveSystem.sceneLoaded += OnSceneLoaded;
...
void OnSceneLoaded(string sceneName, int sceneIndex) // This example assumes script is on the player.
{
    SaveSystem.sceneLoaded -= OnSceneLoaded;
    var positionSaver = GetComponent<PositionSaver>();
    positionSaver.ApplyData(SaveSystem.currentSavedGameData.GetData(positionSaver.key));
}
hidingso
Posts: 26
Joined: Sat Sep 25, 2021 2:07 pm

Re: Load additive scene with spawning

Post by hidingso »

Oh I see, thank you for a quick reply!

I am actually planning on loading scenes additively for "world streaming" purposes, so that makes sense.

I guess I am just wondering what's the ideal way to approach this without having to constantly unload/load my open areas when entering a building and without making things too complex.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Load additive scene with spawning

Post by Tony Li »

In the method in which you load the new location and set a spawnpoint, you can use the code above to ensure that the player's PositionSaver moves the player to that spawnpoint.
Post Reply