Questions about saving again

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lostmushroom
Posts: 195
Joined: Mon Jul 01, 2019 1:21 pm

Questions about saving again

Post by lostmushroom »

Hey Tony. I'm setting up loading and saving in my new game and have a few questions. The save system is mostly working as intended, there are just some things I'd like to polish up, but I'm not sure exactly how.

1. Auto vs manual saving. I've set up 3 save slots for the game. You can currently manually save and load any of them. But there are times where it would be good to have something more like an autosave/load. For example, a continue button on the main menu that loads the last played save. Or a quicksave in the in-game menu that automatically saves to your current slot, rather than making you enter the save slots menu and choose one.
I set up the manual save using SaveSystemMethods.SaveSlot, but this wouldn't work for an autosave, since it requires you to choose a slot to save to. Is there anything like a "save to current slot" equivalent?

2. Is there some way to differentiate between an empty slot and an occupied one? I'd like them to behave slightly differently in some situations. For example, when the player chooses a slot for a new game. If it's empty, a new game should begin immediately, but if it's occupied by a previous save, you might want a warning popup - "This will overwrite..." etc.
Similarly, it would be nice to include some variable information in the save slots depending on whether or not they are empty. If the save slot is occupied, the text might read [var=CharacterName], [var=CurrentLocation], [var=Date], to show your name, location and date, but if it's empty, the text would just read "Empty Slot 1".
Is there an inbuilt way to do something like this, or would it involve some custom scripting?

3. I know this is going to be something really obvious, but how exactly do you make sure that game objects in the scene are getting saved as well as the dialogue data? Just to test this out, I added an Active Saver to a game object, set it to active during a conversation, and set Record Persistent Data On to All Game Objects, but on reloading the game, the game object has returned to its inactive state.

Sorry that's a lot of questions in one go...I'm just trying to get this save system working as well as possible so I never have to look at it again lol. Thanks for your help.
User avatar
Tony Li
Posts: 22115
Joined: Thu Jul 18, 2013 1:27 pm

Re: Questions about saving again

Post by Tony Li »

lostmushroom wrote: Tue Aug 29, 2023 3:05 pm1. Auto vs manual saving. I've set up 3 save slots for the game. You can currently manually save and load any of them. But there are times where it would be good to have something more like an autosave/load. For example, a continue button on the main menu that loads the last played save. Or a quicksave in the in-game menu that automatically saves to your current slot, rather than making you enter the save slots menu and choose one.
I set up the manual save using SaveSystemMethods.SaveSlot, but this wouldn't work for an autosave, since it requires you to choose a slot to save to. Is there anything like a "save to current slot" equivalent?
You could, for example, reserve slot 0 for your autosave and let the player manually save to slots 1-3. Then you could let the player choose to load from slots 1-3 or the autosave in slot 0.

To quick save to the current slot, you'll need to write a little code to record which slot number is the current slot. You could save this in PlayerPrefs. A script with these methods should do:

Code: Select all

using UnityEngine;
using PixelCrushers;
public class AutoSaveMethods : MonoBehaviour
{
    public int CurrentSaveSlot 
    {
        get { return PlayerPrefs.GetInt("CurrentSaveSlot", 0); }
        set { PlayerPrefs.SetInt("CurrentSaveSlot", value); }
    }
    
    public void SaveToSlot(int slot)
    {
        CurrentSaveSlot = slot;
        SaveSystem.SaveToSlot(slot);
    }
    
    public void QuickSave()
    {
        SaveSystem.SaveToSlot(CurrentSaveSlot);
    }
    
    public void QuickLoad()
    {
        if (SaveSystem.HasSavedGameInSlot(CurrentSaveSlot))
        {
            SaveSystem.LoadFromSlot(CurrentSaveSlot);
        }
        else
        {
            Debug.Log($"No saved game in slot {CurrentSaveSlot}");
        }
    }
}
If you save using this script's SaveToSlot instead of SaveSystemMethods.SaveToSlot, it will also record the current save slot number.
lostmushroom wrote: Tue Aug 29, 2023 3:05 pm2. Is there some way to differentiate between an empty slot and an occupied one?
Yes. Check SaveSystem.HasSavedGameInSlot(#).
lostmushroom wrote: Tue Aug 29, 2023 3:05 pmSimilarly, it would be nice to include some variable information in the save slots depending on whether or not they are empty. If the save slot is occupied, the text might read [var=CharacterName], [var=CurrentLocation], [var=Date], to show your name, location and date, but if it's empty, the text would just read "Empty Slot 1".
Is there an inbuilt way to do something like this, or would it involve some custom scripting?
See: How To: Include Summary Info In Saved Games
lostmushroom wrote: Tue Aug 29, 2023 3:05 pm3. I know this is going to be something really obvious, but how exactly do you make sure that game objects in the scene are getting saved as well as the dialogue data? Just to test this out, I added an Active Saver to a game object, set it to active during a conversation, and set Record Persistent Data On to All Game Objects, but on reloading the game, the game object has returned to its inactive state.
You can set the Dialogue Manager's Persistent Data Settings > Record Persistent Data On back to Only Registered. Add the Active Saver to a GameObject that starts active in your scene. Don't add it to an inactive GameObject. If you want to save the active/inactive states of several GameObjects, create an empty active GameObject. Add a Multi Active Saver to it, and assign the GameObjects (which can be inactive or active) to the Targets list. Remember to assign a unique Key such as "sceneName_multiActiveSavers".
lostmushroom
Posts: 195
Joined: Mon Jul 01, 2019 1:21 pm

Re: Questions about saving again

Post by lostmushroom »

Hey Tony, thanks so much. That's all been really helpful. The save system is working pretty much perfectly now. (:
User avatar
Tony Li
Posts: 22115
Joined: Thu Jul 18, 2013 1:27 pm

Re: Questions about saving again

Post by Tony Li »

Glad to help!
Post Reply