Page 1 of 1

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

Posted: Fri Sep 09, 2022 1:52 pm
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.

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

Posted: Fri Sep 09, 2022 2:20 pm
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.

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

Posted: Fri Sep 09, 2022 2:38 pm
by qest43
Work's perfect, your advises are always on point!

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

Posted: Fri Sep 09, 2022 2:49 pm
by Tony Li
Happy to help! :-)