Is it possible to save asynchronously?

Discussion and help for Easy Save 3
Post Reply
doodlinbee
Posts: 23
Joined: Sat Sep 05, 2020 12:53 pm

Is it possible to save asynchronously?

Post by doodlinbee »

I have some checkpoints that auto-saves the game. It saves a lot of data, so I get some frozen frames which makes the gameplay not smooth.

Can I do this saving task aynchronously or something similar?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Is it possible to save asynchronously?

Post by Joel »

Hi there,

Have you followed the Improving Performance guide?
https://docs.moodkie.com/easy-save-3/es ... rformance/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
doodlinbee
Posts: 23
Joined: Sat Sep 05, 2020 12:53 pm

Re: Is it possible to save asynchronously?

Post by doodlinbee »

Hi there!

Yes I have followed the guide. The thing is that I save like 600+ gameobjects so a hiccup seem inevitable when you iterate over that long list and do operations on each objects.

Now the act of saving only freeze the frame for like 0.1 or 0.2 seconds so it's not that dramatic but I would like to get rid of that if possible.

Running a thread with async await is tricky because I sometimes save gameobjects or transforms, and I can only do this in the main thread.

Also in order to have a clean cache each time I save I do "ES3.DeleteFile("Cache");" every time I save. Is this operation costly performance wise? If yes, can I overwrite the cache differently?

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

Re: Is it possible to save asynchronously?

Post by Joel »

Hi there,

Due to the quantity of objects it will be inherently slow to right due to the amount of data.

In this case I would recommend splitting your save calls over multiple frames using a coroutine, rather than doing it over a single frame.

Just to clarify, ES3.DeleteFile isn't a costly operation so you shouldn't need to worry about this.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
doodlinbee
Posts: 23
Joined: Sat Sep 05, 2020 12:53 pm

Re: Is it possible to save asynchronously?

Post by doodlinbee »

Thanks for the clarifications! :D

How would splitting calls over multiple frames would look like in code?

If I have 600 objects, does that mean it will take 600 frames to finish the saving process?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Is it possible to save asynchronously?

Post by Joel »

Hi there,

You would do more than one per frame. For example, 10 per frame could look something like this:

Code: Select all

ES3.Save("gameObjectCount", myGameObjects.Length);

for(int i=0; i<myGameObjects.Length; i++)
{
	ES3.Save("myGameObject"+i, myGameObjects[i]);
	
	// The % is called the modulo operator, and is worth looking up if you've not used it before.
	if(i % 10 == 0)
		yield return null;
}
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply