Removing specific savers from the save data

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Codebread
Posts: 8
Joined: Sat Mar 28, 2020 4:16 pm

Removing specific savers from the save data

Post by Codebread »

I have a series of scenes that are randomly generated when the player enters them. To do this I use a mix of static objects that are created on entry from prefabs (so they have Unique Saver Keys applied) and a bunch of Spawned Objects with Spawned Object Savers attached. Saving and Loading these scenes works perfectly right now. However, I can't think of a clean way to delete this data so when the player leaves and re-enters the scene it's brand new. (In theory I could just clear the Unique Keys and reassign them, but then I would have a bunch of obsolete data in the save file and it would keep growing and growing)

My current solution was to save these specific scenes to a special save file separate from the main save file, resulting in something like:

1) saveGame01.sav
2) saveGame01_GeneratedArea.sav

Then I just delete the "saveGame01_GeneratedArea.sav" when the player leaves the scene. However I realized this method is flawed because any data I want saved globally (player stats, time played, etc) would be applied to only the "saveGame01_GeneratedArea.sav" file while the player is in those scenes. It also just seems like a bad idea to be managing two save files for what is effectively one save slot.

So my question is: is there a way an efficient way to handle this? Such as removing specific save data (savers) from the save file (i don't know how this would work with spawned objects...) or perhaps somehow wiping all save data that is relevant to a specific scene index?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Removing specific savers from the save data

Post by Tony Li »

Hi,

What if you untick the savers' Save Across Scene Changes checkboxes? When the game changes to a different scene, it will purge the saved game data of all saver data from other scenes whose Save Across Scene Changes is unticked.

However, if you save the game in the scene, quit the game, and then reload the game in the scene, the saved game data will still be there because the game hasn't changed to a new scene.
Codebread
Posts: 8
Joined: Sat Mar 28, 2020 4:16 pm

Re: Removing specific savers from the save data

Post by Codebread »

That gets tricky because it's a group of scenes, not a single scene. To use a current popular game as an example think of something like Hades (except you can move back to scenes you already cleared). I need to be able to save the state of multiple "temporary" scenes, and then clear that data out when the player dies.

I did have a thought overnight though: couldn't I simply load the game data and loop through the savers, deleting those that are part of these randomly generated scenes?
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Removing specific savers from the save data

Post by Tony Li »

Hi,

Yes. SaveSystem.currentSavedGameData (which is a SavedGameData object) doesn't expose the DeleteData() method. Here's a patch that does:

PixelCrushersSavedGameDataPatch_2020-12-07.unitypackage

It adds two methods to SaveSystem.currentSavedGameData:
  • DeleteData(key): Removes a Saver's data.
  • GetDataInfo(key): Returns a SaveRecord containing the data and the scene index it was saved in.
Post Reply