Save file disappears on exit.

Discussion and help for Easy Save 3
Post Reply
paul159357
Posts: 4
Joined: Sat Aug 31, 2019 1:31 am

Save file disappears on exit.

Post by paul159357 »

Hi, I'm using easy save 3 on Unity to save my mobile game's data.

Sorry for bad english in advance. I'm trying to explain as best as I can.

I found extremely serious problems after I released this mobile game.

First one was about saving and loading scriptable object. I still don't understand the reason, but when I load one of my custom type scriptable object into default scriptable object that exists on editor, by using script referencing that object, the reference disappears. I use [SerializeField] to put that scriptable object on script, so usually I see that object's name on inspector. However, when I load the data and put it into that object by script, its name becomes empty and whatever I do on that script doesn't change anything on the scriptable object that I can see on editor. Real strange thing is that there are three scriptable objects with same types, but this problem occurs on only one.

Anyway, I solved the first problem by loading data on new local variable at first, and then put each value that loaded one keeps to referenced scriptable object.

Second one is the real problem.

I save some data on exit by using es3.save~ codes on OnApplicationFocus(false). For most cases, it works very well without any problem.

However, sometimes, like less than 1%, when I reopen the app, the whole save datas are gone.

Then I found that some data I saved on OnApplicationFocus was not being saved when I quickly quit my app after app lost focus.

Code was like save A-> save B-> save C, and I found some data of C is neglected and not saved.

I thought it was matter of time, so I reduced the amount of data saved on exit as much as I could.

Still some people report that their whole data are completely gone.

The question is,

1. Should I avoid saving data on exit like that? Is it possible to cause problem if user quits app too quickly when I use es3 codes on exit?

2. Is their anyway to debug this?(ex. see saved data from installed app so that I can be sure is this the problem of loading or saving(exit)->solved, I found the directory on mobile device.)

This occurs scarcely, so it is really hard to replicate. Sorry for little info.

This app is on live and I'm in emergency. Thank you for your fast help in advance.

+I found another strange case. Normally, SaveDta.es3 file with about 8kb should exist on save directory. Once, that file was deleted and only SaveData.es3.tmp of 0B file was there. Still when I reopened the app, save data was loaded without any problem. By the way, can I ask why .tmp files are being generated?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save file disappears on exit.

Post by Joel »

Hi there,

Regarding your first issue, I'm not sure I understand. Please could you create a new, very basic project which replicates it and PM it to me with instructions? (you may need to upload it to something like Google Drive and send me the link).

With regards to using OnApplicationFocus and then quitting, this is expected behaviour. Quitting the app at this point means a hard quit, so code immediately stops executing. Also note that there are cases where OnApplicationFocus is not called (see the Unity doc page for more information on this). OnApplicationPause(true) tends to be more reliable, but this doesn't circumvent the issue of quitting.

If this is an issue, it's recommended that you save at discrete points during your game. For example, when the user completes a level or reaches a checkpoint, or a particular (regularly occurring) event happens.

If you must use OnApplicationFocus, the only way you can account for this is to make backups which you can revert back to if the user quits the app before saving is complete. This minimises the data loss.

With regards to the tmp file, data is first written to a temp file, and once serialisation is complete, the original file is deleted and replaced with the temp file. If you're finding tmp files in your directory, this is usually indicative that the saving process has been interrupted (for example, in the case where you're hard quitting the app before data has a chance to save). You should also make sure you're checking the console/log file for exceptions in case any errors are occurring at runtime which are stopping the execution of the app.

All the best,
Joel

Also as always, I recommend making sure that you're using the latest version of Easy Save.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
paul159357
Posts: 4
Joined: Sat Aug 31, 2019 1:31 am

Re: Save file disappears on exit.

Post by paul159357 »

Thank you Joel,

I'll try to replicate the first issue as soon as I solve the second one.

For most data, I save them on runtime whenever an event occurs, such as level up, as you mentioned. Unfortunately, those data saved on discrete moments are saved in the same file with the ones saved on exit.

There are not many but still some data need to be saved on exit, such as exit time and in-game resources that player can gain every second. Thank you for your recommendation for backup.

I'm still trying to replicate the situation and checking logs, but no success so far.

I'm trying to figure out what exactly is happening to save file for now when they are cleared on next open.

I'll leave another reply here when there is some progress. Again, thank you for your fast reply.
paul159357
Posts: 4
Joined: Sat Aug 31, 2019 1:31 am

Re: Save file disappears on exit.

Post by paul159357 »

Update : Finally replicated the second bug once. No error on adb logcat, file itself was completely erased. I save four parts on exit, and log showed me that the app was force quit before the last one saving code was executed. Still working on.
paul159357
Posts: 4
Joined: Sat Aug 31, 2019 1:31 am

Re: Save file disappears on exit.

Post by paul159357 »

Thank you for your advice. I minimized data save on exit, and also made code that generates back up file every minute. It seems that everything is going well, though still don't understand why quitting while saving causes entire file to vanish. I'll try to replicate first issue on new project and PM you if I succeed. Thank you once again for your help.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save file disappears on exit.

Post by Joel »

Glad the solution appears to be working for you. The most likely reason why the file is erased is because the hard quit occurs at the moment the save file is replaced by the temp file.

If this occurs again and you do find a reliable way of replicating this, please let me know.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply