Page 1 of 1

Is it possible to save asynchronously?

Posted: Wed Jul 20, 2022 3:44 pm
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?

Re: Is it possible to save asynchronously?

Posted: Thu Jul 21, 2022 8:37 am
by Joel
Hi there,

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

All the best,
Joel

Re: Is it possible to save asynchronously?

Posted: Thu Jul 21, 2022 12:18 pm
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,

Re: Is it possible to save asynchronously?

Posted: Thu Jul 21, 2022 1:22 pm
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

Re: Is it possible to save asynchronously?

Posted: Thu Jul 21, 2022 1:29 pm
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?

Re: Is it possible to save asynchronously?

Posted: Fri Jul 22, 2022 10:05 am
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