Frequent saving issues in Idle game

Discussion and help for Easy Save 3
Post Reply
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Frequent saving issues in Idle game

Post by mikemnd »

So long story short, I'm making an idle game and want to save the progress.

Money are changing very frequently also the user can upgrade and buy stuff frequently too.

I looked up: https://docs.moodkie.com/easy-save-3/es ... -the-cache

But I'm not sure if this is going to fix the performance since as I understand the file saving will be with some timer
for example every 10 seconds. But what if the user closes the game?

Should I go and add OnApplicationQuit() in all the spots where is saving or should i just have a single OnApplicationQuit which
should right the cache to a file?

Is there any good practices or common user expectation for saving in Idle games?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Frequent saving issues in Idle game

Post by Joel »

Hi there,

If you're saving every 10 seconds there will still be a significant performance advantage to using caching, even if you're then storing this data to file every 10 seconds. In most cases this will be sufficient to improve performance.

If it's not, storing the cached data in OnApplicationQuit rather than after every 10 seconds will improve performance further.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Frequent saving issues in Idle game

Post by mikemnd »

Thanks for the quick reply and confirming my approach.

I really like the plugin so far and I was impressed about the code generation for custom classes.
It was really easy adding saving support for some custom models with bunch of properties.
That really helped me saving an inventory of items as Dictionary once I've generated the Item model ES3_Type.

One of the next steps I'm looking is a test integration and sync of the ES3 save file in the cloud with Playfab.

If all goes fine I'll share my little case study.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Frequent saving issues in Idle game

Post by Joel »

Glad you're finding it useful :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Frequent saving issues in Idle game

Post by mikemnd »

Hi Joel,

I've found this thread: Work with Coroutines

Also I researched a bit more and saving on different thread and across several frames looks like the best way to handle the frequent saving.

Does EasySave3 have something integrated or is the approach the same as the one in the ES2 topic?
Also is there a difference if I save the different keys in the save file or a 1 key?
Do ES3 loads the whole file in memory and than write out all of the content or is there some smart optimizations?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Frequent saving issues in Idle game

Post by Joel »

Hi there,
Also I researched a bit more and saving on different thread and across several frames looks like the best way to handle the frequent saving.
There would be little benefit in saving over multiple frames vs saving using caching.
Does EasySave3 have something integrated or is the approach the same as the one in the ES2 topic?
For your use case there wouldn't be much benefit of using threading over using caching as described in the Improving Performance guide. However, if you do decided to use threading, you would need to create your own thread to do this.
Also is there a difference if I save the different keys in the save file or a 1 key?
I'm afraid I don't understand your question. Please could you clarify?
Do ES3 loads the whole file in memory and than write out all of the content or is there some smart optimizations?
If you use caching then it will load the entire file in memory and load from this. Otherwise, it will load directly from the file. Generally there are no 'smarter' optimisations when it comes to File I/O.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Frequent saving issues in Idle game

Post by mikemnd »

Ok thanks for the answers.

About this one:
Also is there a difference if I save the different keys in the save file or a 1 key?
Is there difference if I do a method which calls:

Code: Select all

ES3.Save("coins", _coins);
ES3.Save("gems", _gems);
ES3.Save("inventory", _inventory);
Or if I do only one of them?

Code: Select all

ES3.Save("coins", _coins);
At the moment I have a method that call Save on each of the objects/managers that need to be saved.
If I separate the calls to save only coins, and later on only gems should it be better in term of performance?
All of the above data is saved in a single save file - since the game autosaves and player doesn't have a choice when and where to save.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Frequent saving issues in Idle game

Post by Joel »

Hi there,

Splitting it across frames is unlikely to make any noticeable difference if you're using caching.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
mikemnd
Posts: 11
Joined: Wed Dec 30, 2020 4:11 pm

Re: Frequent saving issues in Idle game

Post by mikemnd »

Ok I've set it up with Caching and it works ok for now :)

The only strange thing was that even thou I've set the default path in the Unity UI in the ES3 panel
I still needed to call:

Code: Select all

ES3.CacheFile("Saves/IAF_Save.es3", Settings);
With the full path otherwise the Loading from the persistent file to the cache did not happen.
Post Reply