Always validate loading.
if (!File.Exists(path))
{
return CreateDefaultData();
}
Handle unexpected errors:
try
{
string json =
File.ReadAllText(path);
SaveData data =
JsonUtility.FromJson<SaveData>(
json
);
}
catch (System.Exception error)
{
Debug.LogError(
"Save load failed: " +
error.Message
);
}
You can also keep a backup save file for recovery.