Simple Save and Load from SAV File

Announcements, support questions, and discussion for the Dialogue System.
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Ahh got it to work! I had to check "Skip Apply Data After Frames If Apply Immediate" and it started loading the games correctly. I'll do a bit more testing but I think it's working now after 5 load attempts.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple Save and Load from SAV File

Post by Tony Li »

Hi -- you beat me to it. :-) I was writing up these suggestions:


I recommend using the default values for the DialogueSystemSaver component (Save Across Scene Changes & Skip Apply Data After Frames If Apply Immediate both ticked).

Also, saving and loading may take more than one frame. (If you must absolutely save in one frame, such as when exiting the application, call SaveSystem.SaveToSlotImmediate(#).)

To know when the load is complete, use the C# event SaveSystem.loadEnded. For example:

Code: Select all

SaveSystem.loadEnded += OnLoadEnded;
SaveSystem.LoadFromSlot(slotNumber);
...
void OnLoadEnded()
{
    SaveSystem.loadEnded -= OnLoadEnded;
    SceneHubContinue(); ...
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Perfect, thanks for the suggestions! I'm trying to do a visual novel style system with a realtime clock that saves every in-game hour.

The "hub" that all the other scenes stem from keeps the time and the others have a separate time instance, so I didn't want them to save on scene change.

Is SaveToSlotImmediate the recommended way to save? I set it to only save in-game hour to an autosave and manual save buttons to save to individual slots.

Also if I choose custom data path for the disk saver, how would I set it to have a separate folder inside the gamefolder? Like Game/Save/save_5.dat
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple Save and Load from SAV File

Post by Tony Li »

Hi,

SaveToSlot() is the recommended way to save, but either is fine unless you're saving while exiting the application (in which case use SaveToSlotImmediate(). SaveToSlot() has these two differences:

1. It waits 1 frame before starting the save process to allow UIs to update (e.g., show a "save in progress" icon).

2. It allows the SavedGameDataStorer to take as many frames as it needs to store the saved game data.

In contrast, SaveToSlotImmediate():

1. Does not wait 1 frame.

2. Tells the SavedGameDataStorer to save immediately, not taking any extra frames.

If you choose custom data path, you can specify it in the Custom Path field or set customPath in your own code. Example:

Code: Select all

SaveSystem.instance.GetComponent<DiskSavedGameDataStorer>().customPath = $"{Application.persistentDataPath}/Save";
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Perfect, working just as intended, I'll stick with SaveToSlot then since I don't want to save on exit. Thanks a bunch Tony!
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Simple Save and Load from SAV File

Post by Tony Li »

Happy to help!
Post Reply