Save system - how to load basic scene if there is no save on slot

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
qest43
Posts: 33
Joined: Thu May 26, 2022 9:22 am

Save system - how to load basic scene if there is no save on slot

Post by qest43 »

I have this code:

Code: Select all

        public void OnSlotPressed()
        {
            int active_slot = GameManager.Instance.currentSaveSlot;
            SaveSystem.LoadScene("Area 0");
            if (SaveSystem.HasSavedGameInSlot(active_slot)) SaveSystem.LoadFromSlot(active_slot);
        }
So I am loading basic scene Area 0, and then I am loading save according to pressed slot, 1,2 or 3 and assign that number to active_slot var here. If all slots has no saves, and I choose slot number 1 for example and then save progress, then back to menu and choose for example slot 2 or 3 that is empty, game loads status from slot number 1, but should load basic scene Area 0. I dont know I explained it well but I dont know how to load basic scene in case if there is no save on slot.
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save system - how to load basic scene if there is no save on slot

Post by Tony Li »

Hi,

The Dialogue System's save system can save and restore the current scene that the player is in. That might make it simpler. To tell the save system to remember which scene the player was in, tick the Save System component's "Save Current Scene" checkbox. (This checkbox is ticked by default.)

Then you can use code like this:

Code: Select all

if (SaveSystem.HasSavedGameInSlot(active_slot))
{
    SaveSystem.LoadFromSlot(active_slot);
}
else
{
    SaveSystem.RestartGame("Area 0");
}
Note: Alternatively, you can add a Save System Methods component to a UI Button GameObject. Then configure the UI Button's OnClick() event to call SaveSystemMethods.LoadOrRestart(slot#). If there is a saved game in the slot, it will load it. Otherwise it will restart a new game at the scene specified by the Save System Methods component's Default Starting Scene Name.
qest43
Posts: 33
Joined: Thu May 26, 2022 9:22 am

Re: Save system - how to load basic scene if there is no save on slot

Post by qest43 »

Work's perfect, your advises are always on point!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save system - how to load basic scene if there is no save on slot

Post by Tony Li »

Happy to help! :-)
Post Reply