I am saving my data to playerprefs. Saving works perfect, never any issues. Issues come up when loading the data. If at any point when I’m loading all my data, if I encounter a null pointer exception, then my method for loading my data stops and only part of the data is loaded. When the real issue happens is if this null pointer issue occurs and then default data is saved the player will lose some of their progress, if not all of it.
Example:
Load stats - Complete
Load player position - Complete
Load equipment - failed null pointer
Load inventory - never called
Load quests completed - never called
ect…
From this point we loaded into the game with an empty inventory and no quests completed. Then the game auto saves, we lost pretty much everything in this case…
So my question is how do I create a fail safe save system? Can I do try catch for each section that is loaded? Even in that case if something fails we might still load the game with partial data, in that case we wouldn’t want to save. We could create multiple previous save states but this is tedious for the player to manage if there are issues.
I just need a solution to where if one thing fails to load that it doesn’t cause everything to fail. So if one piece of equipment fails it doesn’t effect the other equipment. Or if an inventory item fails to load that it doesn’t cause the entire inventory to not load or the other methods to load.