Page 1 of 1
Save slots seem to be deleting themselves
Posted: Thu Jan 30, 2020 9:07 pm
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?
Re: Save slots seem to be deleting themselves
Posted: Thu Jan 30, 2020 9:50 pm
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.
Re: Save slots seem to be deleting themselves
Posted: Fri Jan 31, 2020 9:44 pm
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.
Re: Save slots seem to be deleting themselves
Posted: Fri Jan 31, 2020 11:28 pm
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.
Re: Save slots seem to be deleting themselves
Posted: Mon Feb 03, 2020 2:57 pm
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!
Re: Save slots seem to be deleting themselves
Posted: Mon Feb 03, 2020 3:07 pm
by Tony Li
Glad you found the issue!