Quick clarification about sync()

Discussion and help for Easy Save 3
Post Reply
David_Nightcap
Posts: 10
Joined: Sun Apr 12, 2020 1:18 pm

Quick clarification about sync()

Post by David_Nightcap »

I see that the documentation says "Synchronises this ES3File with a file in storage." for sync().
But what EXACTLY does that mean?

I'm running into an issue where I save a bunch of stuff to the ES3 file and it looks right in memory and it also is writing it to the file after every ES3.Save() call. Great! Except when I call sync() it wipes all the changes in the save file and replaces it with the original version that ES3 opened. Is this the intended behavior? I thought calling sync() was the moment of commitment that would write everything in memory to the file and sync memory & file on disk. Is that wrong?

Thanks!

User avatar
Joel
Moodkie Staff
Posts: 2971
Joined: Wed Nov 07, 2012 10:32 pm

Re: Quick clarification about sync()

Post by Joel »

Hi there,

ES3File has been replaced by the ES3.Location.Cache storage location which is documented here, which is clearer on how it's used:
https://docs.moodkie.com/easy-save-3/es ... rformance/

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

David_Nightcap
Posts: 10
Joined: Sun Apr 12, 2020 1:18 pm

Re: Quick clarification about sync()

Post by David_Nightcap »

Hmmmm....I must not be up to date on the latest version since ES3.Location.Cache isn't found.
I'm also reluctant to upgrade since I'm shipping within the next few months.
Also, will ES3.Location.Cache work on consoles?

Can I safely just remove the ES3.Sync() call? It seems to be writing to the file just fine before it gets to that point.
I'm not sure where I got that ES3.Sync() needed to be called when saving to disk.

Thanks again.

User avatar
Joel
Moodkie Staff
Posts: 2971
Joined: Wed Nov 07, 2012 10:32 pm

Re: Quick clarification about sync()

Post by Joel »

Hi there,

If you do not have the Cache location then you are on an older version.

Just to clarify, an ES3File will not write to file unless Sync is called, so I'm not sure how yours is writing to file without calling this.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

David_Nightcap
Posts: 10
Joined: Sun Apr 12, 2020 1:18 pm

Re: Quick clarification about sync()

Post by David_Nightcap »

Hmmm...I have no idea how it's writing to disk after every save but the fact it's not supposed to is concerning.
I have no changes to ES3 locally and my code is very simple.

I have the save file open in a text editor so I can watch it. Stepping through with a debugger, after every ES3.Save() it updates the file with the new data. If I call cache.Sync() at the end of SaveAllData(), it reverts the file back to the original file it loaded when the game started.

Here's the bare bones of the code. I've stripped out everything non ES3 related:

Code: Select all

public class PersistentDataManager : MonoBehaviour
{
    public ES3Settings settings;
    public ES3File cache;

    public void Initialize()
    {
        settings = new ES3Settings();
        settings.location = ES3.Location.File;
        settings.directory = ES3.Directory.PersistentDataPath;
        cache = new ES3File(settings);
        
        LoadAllData();        
    }
    
    
    public void LoadAllData()
    {       
         cache.Sync();
    }
    
     public void SaveAllData()
     {         
         string sceneName = SceneManager.GetActiveScene().name;
         ES3.Save<string>("Global_Scene", sceneName);
    
         // Tons of ES3.Save() calls like the one above
         
         cache.sync()   // This is the offending line
         
      }
 }
Any ideas?

User avatar
Joel
Moodkie Staff
Posts: 2971
Joined: Wed Nov 07, 2012 10:32 pm

Re: Quick clarification about sync()

Post by Joel »

Hi David,

I think you might be confused around how ES3File works. To write to the cached ES3File, you would do cache.Save(key, value). However, you're then using ES3.Save, which will write directly to file.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

David_Nightcap
Posts: 10
Joined: Sun Apr 12, 2020 1:18 pm

Re: Quick clarification about sync()

Post by David_Nightcap »

OMG it's so obvious. I'm so embarrassed I didn't notice this before.
I began work on this months ago and returned to it and must have just copy/pasted the ES3.Save() instead of cache.Save() as I was fleshing it out.
Sorry for the bonehead question but thank you for clearing it up!

User avatar
Joel
Moodkie Staff
Posts: 2971
Joined: Wed Nov 07, 2012 10:32 pm

Re: Quick clarification about sync()

Post by Joel »

No problem, let me know if you run into any other issues :)

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

Post Reply