SaveSystem and Additive Scene Loading

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mroshaw
Posts: 96
Joined: Wed Jan 19, 2022 4:10 am

SaveSystem and Additive Scene Loading

Post by mroshaw »

Hi again!

Sorry to raise two tickets in one day - load / save is my mission this weekend!

My project uses additive scene loading. My implementation is to have a "Master Scene" that contains a custom "Additive Scene Loader" component. This component, in the OnStart event, iterates through a list of scenes and calls SceneManager.LoadSceneAsync. The component invokes a UnityEvent once all scenes have been loaded, and another event once all scenes have been activated. I have a "Base Scene" that contains game managers, lighting, baked NavMesh etc, and that scene is set as the "Active Scene" in SceneManager, by the component code. Additional scenes contain terrain, scenery, NPCs, etc.

This "Master Scene", alongside the Additive Scene Loader, manages a loading screen and progress bar, calculated on the progress of the combined progress of all async load processes.

My hierarchy looks like this:

- Master Game Scene
|- Additive Scene Loader
|- Game Controller
|- UI Manager
|- Camera Manager
- Game Terrain Scene
|- All Terrain
- Base Scene
|- Ocean
|- Spawners
|- Quest Machine and Dialogue
|- Enviro
- Small Settlements Scene
- Medium Settlements Scene
- Large Settlements Scene

I was wondering if there's a pattern that I can adapt to use SaveSystem with this setup?

What I've tried so far, is to add my SaveSystem to the "Master Scene". What I've found, however, is that when I SaveGame, the save is created in the context of the "Active Scene", that is "Base Scene". Therefore, none of the additive scene-loading script is run.

I'm assuming there's more complexity that I haven't accounted for yet, such as managing Saver components across multiple scenes.

I was hoping a poke in the right direction might send me on my way?

I know this is a very specific implementation question, so my expectations are set that there's only so much help you can offer.

Many thanks again!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: SaveSystem and Additive Scene Loading

Post by Tony Li »

Hi,

What do you mean by the save being created in the context of the active scene? Are only the savers in the active scene being saved?

To additively load and unload scenes, can you use SaveSystem.LoadAdditiveScene() and UnloadAdditiveScene() instead of SceneManager? Internally, these methods use SceneManager, but they also do some housekeeping related to the save system.
mroshaw
Posts: 96
Joined: Wed Jan 19, 2022 4:10 am

Re: SaveSystem and Additive Scene Loading

Post by mroshaw »

Thanks Tony.

By that, I mean when I call SaveSystem.LoadFromSlot(), it's loading up the "Base Scene", rather than the "Master Scene". I assume because as part of the additive loading process, I make "Base Scene" the active scene (SceneManager.SetActiveScene()).

Does that make sense?

I tried unchecking "Save Current Scene" in the SaveSystem component. When I then call LoadFromSlot(), however, nothing seems to happen. Even SaveSystem.loadEnded() doesn't seem to be triggered.

Oli
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: SaveSystem and Additive Scene Loading

Post by Tony Li »

Hi Oli,

Since you're using multiple scenes, keep the 'Save Current Scene' checkbox UNticked. Handle scene loading yourself, then call SaveSystem.LoadFromSlot() to apply save game data to the savers in the loaded scenes.

If you want, you can write a custom saver that saves the list of scenes that are currently open. Then, before loading the saved game, retrieve the saver's data using SaveSystem.storer.RetrieveSavedGameData(), and get the saver's saved game data using SavedGameData.GetData().
mroshaw
Posts: 96
Joined: Wed Jan 19, 2022 4:10 am

Re: SaveSystem and Additive Scene Loading

Post by mroshaw »

Superb, thanks Tony! That makes complete sense, and means I can also keep my additive loading code as is, and handle the ApplyData and dataApplied stuff nice and clean.

Absolutely brilliant mate, thank you again. And sorry to disturb your Sunday. I'll keep new questions to the working week from now on!

Oli
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: SaveSystem and Additive Scene Loading

Post by Tony Li »

Glad to help!
Post Reply