Save slots seem to be deleting themselves

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Save slots seem to be deleting themselves

Post by VoodooDetective »

So I'm using the Disk Saved Game Data Storer and here's what happens.

I create a save in slot 1
I create a save in slot 2

I stop the editor
I start the editor

I delete the save in slot 1
I recreate the save in slot 1

I try to load slot 2. Slot 2 is empty. Is this expected behavior?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save slots seem to be deleting themselves

Post by Tony Li »

Hi,

How are you deleting the slot? The DiskSavedGameDataStorer component maintains a catalog of save files in a file named saveinfo.dat. This catalog also needs to be kept up to date. The best way to delete a slot is to call SaveSystem.DeleteSavedGameInSlot(#), or call the DiskSavedGameDataStorer component's DeleteSavedGameData(#) method directly.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: Save slots seem to be deleting themselves

Post by VoodooDetective »

Hmm I could just be really confused. Here's the code I'm seeing:

Code: Select all


        public virtual void UpdateSavedGameInfoToFile(int slotNumber, SavedGameData savedGameData)
        {
            var slotIndex = slotNumber;
            for (int i = m_savedGameInfo.Count; i <= slotIndex; i++)
            {
                m_savedGameInfo.Add(new SavedGameInfo(string.Empty));
            }
            m_savedGameInfo[slotIndex].sceneName = (savedGameData != null) ? savedGameData.sceneName : string.Empty;
            var filename = GetSavedGameInfoFilename();
            if (debug) Debug.Log("Save System: DiskSavedGameDataStorer updating " + filename);
            try
            {
                using (StreamWriter streamWriter = new StreamWriter(filename))
                {
                    for (int i = 0; i < m_savedGameInfo.Count; i++)
                    {
                        streamWriter.WriteLine(m_savedGameInfo[i].sceneName.Replace("\n", "<cr>"));
                    }
                }
            }
            catch (System.Exception)
            {
                Debug.LogError("Save System: DiskSavedGameDataStorer - Can't create file: " + filename);
            }
        }
That get's called every time I delete a game. Maybe I'm reading it wrong, but it seems like

First it deletes the save game, which is fine. But then when it's updating the saveinfo.dat,

1) it iterates over all current games in memory up until the save slot index you want to delete adding empty save game info to the in memory list of save games.
2) Then it sets the slot to delete's sceneName.
3) Then it writes out that list of mostly empty stuff to disk.

Am I reading that wrong / misunderstanding? So whenever I try to delete just the second slot, it does delete the save game file, but it also wipes the saveinfo.dat so that it looks like there never was a save game in slot 1.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save slots seem to be deleting themselves

Post by Tony Li »

Hi,

If you delete save 1, it will still keep the save info for slot 2, and vice versa.

When you delete a saved game, it passes null to the UpdateSavedGameInfoToFile method, which makes it record an empty string in the slot info's sceneName field. Here's an annotated version of the method:

Code: Select all

public virtual void UpdateSavedGameInfoToFile(int slotNumber, SavedGameData savedGameData)
{
    // If the slot number is greater than the current number of slots recorded  in the saved game info list,
    // add more entries to the saved game info list:
    var slotIndex = slotNumber;
    for (int i = m_savedGameInfo.Count; i <= slotIndex; i++)
    {
        m_savedGameInfo.Add(new SavedGameInfo(string.Empty));
    }
    
    // In the saved game info list element for the slot number, record the saved game data's scene name:
    m_savedGameInfo[slotIndex].sceneName = (savedGameData != null) ? savedGameData.sceneName : string.Empty;
    
    // Write the entire saved game info list to the saveinfo.dat file:
    var filename = GetSavedGameInfoFilename();
    if (debug) Debug.Log("Save System: DiskSavedGameDataStorer updating " + filename);
    try
    {
        using (StreamWriter streamWriter = new StreamWriter(filename))
        {
            for (int i = 0; i < m_savedGameInfo.Count; i++)
            {
                streamWriter.WriteLine(m_savedGameInfo[i].sceneName.Replace("\n", "<cr>"));
            }
        }
    }
    catch (System.Exception)
    {
        Debug.LogError("Save System: DiskSavedGameDataStorer - Can't create file: " + filename);
    }
}
}
Please feel free to send me a reproduction project and steps to reproduce the issue. I'll be happy to take a look.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: Save slots seem to be deleting themselves

Post by VoodooDetective »

Ah I figured it out. I was trying to delete a game in Start() and I guess the save system isn't initialized until Start(). Sorry for the confusion, and thanks for looking at it!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save slots seem to be deleting themselves

Post by Tony Li »

Glad you found the issue!
Post Reply