Prevent save loss
Prevent save loss
I have a saver component that remembers the last scene the player was in. If I delete that scene, Players who were stuck there will no longer be able to load their save file.
1. How can I throw an exception in this situation? I use "LoadOrRestart()" function.
One way I thought of is have a variable that keeps track of important levels that will never get deleted, and when you enter one of those have the variable update, but I don't know how I could plug that in to the mainmenu play button to check if save could not load, to load that level.
I use LoadLevel sequence command to load mini levels.
2. Also what if I rename a scene that some players had a save in? Will they also not be able to load that level?
This is definitely not a corrupted save file, but it sure could feel like it to a player, and the longer they spend playing the game, the worse it feels to lose a save file.
1. How can I throw an exception in this situation? I use "LoadOrRestart()" function.
One way I thought of is have a variable that keeps track of important levels that will never get deleted, and when you enter one of those have the variable update, but I don't know how I could plug that in to the mainmenu play button to check if save could not load, to load that level.
I use LoadLevel sequence command to load mini levels.
2. Also what if I rename a scene that some players had a save in? Will they also not be able to load that level?
This is definitely not a corrupted save file, but it sure could feel like it to a player, and the longer they spend playing the game, the worse it feels to lose a save file.
Re: Prevent save loss
That's a good catch. If you remove or rename the scene whose name is stored in the saved game file, then it won't load that scene.
I'll add a method hook to the SaveSystem class that you can use to validate a scene name before the Save System tries to load it. It will work something like:
I'll add a method hook to the SaveSystem class that you can use to validate a scene name before the Save System tries to load it. It will work something like:
Code: Select all
using UnityEngine.SceneManagement;
using PixelCrushers;
...
SaveSystem.validateSceneName = ValidateSceneName;
...
public string ValidateSceneName(string sceneName)
{
int index = SceneUtility.GetBuildIndexByScenePath(sceneName);
if (index >= 0)
{
return sceneName; // Scene is valid.
}
else
{
return "DefaultSceneToLoadIfSceneNameDoesNotExist; // Some scene to load as a fallback.
}
}
Re: Prevent save loss
Could you please send it to me as a mini package to overwrite my current version? I am trying to stay on the same version of this asset without upgrading during production.
I am afraid to mess with it even a little bit and screw the files of hundreds of my players in the process.
Thank you for your kindness, if you do.
I am afraid to mess with it even a little bit and screw the files of hundreds of my players in the process.
Thank you for your kindness, if you do.
Re: Prevent save loss
Hi,
Please back up your project, or at least SaveSystem.cs, and import this patch:
PixelCrushers_SaveSystemPatch_2022-08-05.unitypackage
There haven't been too many changes that affect any scripts outside of SaveSystem.cs, so you probably won't need to update any other scripts. If you do need to make changes and aren't sure how to proceed, just let me know.
Please back up your project, or at least SaveSystem.cs, and import this patch:
PixelCrushers_SaveSystemPatch_2022-08-05.unitypackage
There haven't been too many changes that affect any scripts outside of SaveSystem.cs, so you probably won't need to update any other scripts. If you do need to make changes and aren't sure how to proceed, just let me know.
Re: Prevent save loss
I get 3 errors at line 436 and 682
For reference I'm on version 2.2.25.1 of the asset, so probably quite far behind.
For reference I'm on version 2.2.25.1 of the asset, so probably quite far behind.
- Attachments
-
- 2.png (72.9 KiB) Viewed 658 times
-
- 1.png (46.84 KiB) Viewed 658 times
Re: Prevent save loss
Hi,
Unless you've made changes to SavedGameData.cs and StandardSceneTransitionManager, you can import them from version 2.2.30. That should resolve the errors.
Unless you've made changes to SavedGameData.cs and StandardSceneTransitionManager, you can import them from version 2.2.30. That should resolve the errors.
Re: Prevent save loss
I have a "Play" button on the main menu that triggers LoadOrRestart() on click.
1. What change do I need to do to check?
Also can I use DialogueSystem.GetVariable() in a script to get a saved string variable from the save file? That variable would be updated on Start() when loading an important scene.
2. To save, I call SaveSystemMehotds.SaveSlot(0)
If I want to allow multiple save files, how would I save instead?
1. What change do I need to do to check?
Also can I use DialogueSystem.GetVariable() in a script to get a saved string variable from the save file? That variable would be updated on Start() when loading an important scene.
2. To save, I call SaveSystemMehotds.SaveSlot(0)
If I want to allow multiple save files, how would I save instead?
Re: Prevent save loss
SealDev wrote: ↑Fri Aug 05, 2022 2:12 pm1. What change do I need to do to check?
What do you mean? LoadOrRestart will check if a saved game exists in the specified slot. If so, it will load that game. Assuming your SaveSystem component's Save Current Scene checkbox is ticked, this will make it try to load the scene in which the game was saved. With this patch, it will call SaveSystem.validateSceneName first. In most cases, validateSceneName should just return the same scene name that it was provided. However, if that scene name is no longer a scene that's in build settings, return some other scene name instead -- for example, maybe the game's world map scene or home scene.
This post shows how to extract data from a saved game. The Dialogue System's variables are in Lua, so unless you store the value elsewhere you'll have to run the data through Lua to get at the individual variable value.
Pass a different slot number. SaveSlot(0) refers to slot 0. You can use any numbers for slots.
Re: Prevent save loss
Can I invoke on Start? Or anywhere really? (1.png)
I have a Dialogue System Trigger, OnDataApplied that runs (2.png) to get the HubWorld lua variable in the main menu.
On a huge database size, does OnDataApplied take longer to run? Should I be worried about a player clicking the play button quicker than it takes to retrieve the lua variable? Asking as my project grows a lot over time.
If I set a new HubWorld at some point, then you click the play button before retrieving the data from the save file, it will only load the default variable value, instead of the one I set?
I have a Dialogue System Trigger, OnDataApplied that runs (2.png) to get the HubWorld lua variable in the main menu.
On a huge database size, does OnDataApplied take longer to run? Should I be worried about a player clicking the play button quicker than it takes to retrieve the lua variable? Asking as my project grows a lot over time.
If I set a new HubWorld at some point, then you click the play button before retrieving the data from the save file, it will only load the default variable value, instead of the one I set?
- Attachments
-
- 1.png (29.29 KiB) Viewed 574 times
Last edited by SealDev on Sun Aug 07, 2022 7:51 am, edited 2 times in total.