To avoid having to maintain customizations to SaveSystem.cs, I recommend unticking "Save Current Scene".
Write a saver script that records the current additively-loaded scene(s) and also marks the persistent scene as the current scene to load when loading saved games. Assuming the persistent scene is named "Persistent", there's a rough example: (may have typos)
Code: Select all
public class SceneSaver : Saver
{
[Serializable]
public class Data
{
public List<string> addedScenes;
}
public override string RecordData()
{
// Update the current saved game data so the "Persistent" scene is the main scene to load:
SaveSystem.currentSavedGameData.sceneName = "Persistent";
// Then save the list of additively-loaded scenes:
var data = new Data() { addedScenes = new List<string>(SaveSystem.addedScenes); }
return SaveSystem.Serialize(data);
}
public override void ApplyData(string s)
{
if (string.IsNullOrEmpty(s)) return;
var data = SaveSystem.Deserialize<Data>(s);
if (data == null) return;
foreach (string sceneName in data.addedScenes)
{
SaveSystem.LoadAdditiveScene(sceneName);
}
}
To load a saved game, just load it normally using the SaveSystem (e.g., SaveSystem.LoadFromSlot(#)).
To change scenes, load the next scene additively and unload the outgoing scene. You can use SaveSystem.sceneLoaded to know when to unload the outgoing scene:
Code: Select all
SaveSystem.sceneLoaded += OnSceneLoaded;
SaveSystem.LoadAdditiveScene(nextSceneName);
...
void OnSceneLoaded()
{
SaveSystem.sceneLoaded -= OnSceneLoaded;
SaveSystem.UnloadAdditiveScene(outgoingSceneName);
}