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

Simple Save and Load from SAV File

Post by xyztankman »

Hey Tony,

I am trying to make a save file similar to the way RPG maker games do their save files:

- Game Folder/Save/ and the SaveData is listed in the folder
-Filetype .sav

I have a Disk Saved Game Data Storer set on my Dialogue Manager set to Data Path but it doesn't seem to save my data in an editable way like Sav does. Also only 1kb.

I also have a PlayerPrefs Saved Game Data Storer, Dialogue System Saver and the Game Summary Saver on my Dialogue Manager from a tutorial you posted which is working great.
Attachments
Save.png
Save.png (107.42 KiB) Viewed 744 times
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 should have only one ***SavedGameDataStorer component on the same GameObject as the SaveSystem GameObject. If you want to save to disk, keep the DiskSavedGameDataStorer and remove the PlayerPrefsSavedGameDataStorer.

There are a few settings on DiskSavedGameDataStorer that let you customize where and how it saves. But if you need it work even more differently (e.g., like RPG Maker), then you can make your own custom subclass of SavedGameDataStorer or DiskSavedGameDataStorer and use that.

If you tick the JsonDataSerializer's Pretty Print, it will format the save data in a more human-readable way with line breaks and indents.

p.s. - Make sure to assign unique Keys to your savers.
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

The Saved data type storer hit me when I was typing it out...figured you couldn't save to both playerprefs and a disk save at the same time.

Ok so I removed the PlayerPrefsSavedGameDataStorer but now I am receiving an error after entering a key for the Dialogue System Saver as "Save". I also checked "Append Saver Type to Key" for both the Dialogue System Saver and Game Summary Saver. Is this the correct way to use the key?

In my CheckSave function it has strings for getting the savedGameData. Right now I'm getting a null reference exception when it does the check
Attachments
Save1.5.png
Save1.5.png (70.99 KiB) Viewed 727 times
Save1.png
Save1.png (67.48 KiB) Viewed 727 times
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,

Which line is raising the error?

Whenever you get a value from a function, I recommend checking if it's null. For example:

Code: Select all

var savedGameData = SaveSystem.storer.RetrieveSavedGameData(1);
if (savedGameData == null)
{
    Debug.LogError("Unable to retrieve saved game data from slot 1.");
}
else
{
    string s = savedGameData.GetData("Save");
    string g = savedGameData.GetData("GameSummary");
    if (string.IsNullOrEmpty(s))
    {
        Debug.LogError("Unable to get save data under key 'Save' in savedGameData.");
    }
    else if (string.IsNullOrEmpty(g))
    {
        Debug.LogError("Unable to get save data under key 'GameSummary' in savedGameData.");
    }
    else
    {...
For example, this may suggest to you that the key is incorrect. If you've set the Dialogue System Saver's Key field to "Save" and also ticked "Append Saver Type To Key", then the actual key will be "Save_DialogueSystemSaver", so in this case you will need to untick "Append Saver Type To Key" or use:

Code: Select all

string s = savedGameData.GetData("Save_DialogueSystemSaver");
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Ahh ok, it started at the Load1_Day.text, but I didn't know that append saver type to key added _DialogueSystemSaver. That seemed to be the issue, now the save files are working as intended from my tests in editor! I'll test in a build shortly to see if it still works as intended.
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Just tested a build and save files are working correctly! Easily editable as well which is great. Thanks 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 »

Great! Glad to help.
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Hey Tony, so ran into a new issue after this regarding loading the file.

I've checked the save files in the game folder and the data is showing correctly but when I click load none of the game variables reload with it.

In the screenshot I went to day 10, saved a file (which saved correctly) and then attempted to load from the current scene, main menu and after closing and reopening the game.

- Current scene and main menu:
No change from the current session and stayed on Day 10 with the same clock time

- Close and reopen the game:
Starts from day 1 variables
Attachments
Save4.png
Save4.png (13.5 KiB) Viewed 657 times
Save3.png
Save3.png (91.04 KiB) Viewed 657 times
Save2.png
Save2.png (574.05 KiB) Viewed 657 times
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,

Have you manually edited the save file? If so, it doesn't look like it's in a valid format.

Are there any errors or warnings in the Console window?

Have you fully configured the save system, including adding a DialogueSystemSaver component to the Dialogue Manager and assigning a unique key such as "ds"?
xyztankman
Posts: 54
Joined: Mon Jun 21, 2021 7:48 pm

Re: Simple Save and Load from SAV File

Post by xyztankman »

Tony Li wrote: Wed Aug 14, 2024 8:11 am Hi,

Have you manually edited the save file? If so, it doesn't look like it's in a valid format.

Are there any errors or warnings in the Console window?

Have you fully configured the save system, including adding a DialogueSystemSaver component to the Dialogue Manager and assigning a unique key such as "ds"?
Hey Tony, no manual editing of the save file, I just added some line breaks for readability in the screenshot. No errors or warnings either, my save system didn't have any changes either except for switching to the disk saved game storer.

I set the dialogue manager debug level to info and it seems that everything is working except when loading, it loads the current data again instead of the save file.
Attachments
Save6.png
Save6.png (108.85 KiB) Viewed 631 times
Save5.png
Save5.png (105.34 KiB) Viewed 631 times
Post Reply