Page 1 of 1

[HOWTO] How To: Change Scenes With Save System

Posted: Thu Dec 24, 2020 9:20 am
by Tony Li
When changing scenes, you can use the Pixel Crushers Save System to record the state of the old scene before leaving, and then restore the saved state of the new scene after entering. Otherwise, when you leave the old scene, you'll lose the player's progress in it; and when you enter the new scene, it will have its original design-time state without any progress that the player may have made in it.

To change scenes with the save system, use any of these techniques:
  • In C#: PixelCrushers.SaveSystem.LoadScene("sceneName") or LoadScene("sceneName@spawnpoint")
  • In a sequence: LoadLevel("sceneName") or LoadLevel("sceneName", "spawnpoint")
  • Using a Scene Portal component.
  • By calling SaveSystemMethods.LoadScene (e.g., add to a UI Button and call in OnClick() event).
If you must change scenes some other way, then before changing scenes call:

Code: Select all

PixelCrushers.SaveSystem.RecordSavedGameData();
PixelCrushers.SaveSystem.BeforeSceneChange();
After changing scenes, call:

Code: Select all

PixelCrushers.SaveSystem.ApplySavedGameData();
See also: