Is it normal that saving data to file makes game freeze for a long time?
Hi, it's the first time I'm trying to save data in a game, so I don't really know what are normal performance. I am using Easy Save 3 asset.
When I save variables my game freeze for about 4-5 seconds. I have a loop that save around 160 variable int to a file, I thought that wasn't a lot but it's a lot? When bigger have thousands of stats and data everywhere I didn't expect to save 160 int so a file would be a problem and make my game lag for multiple seconds. The problem is that my game is for android, so even if I put the save on exit or on pause, if the person exist the app completely (swiping up from app tray to remove from cache), my game doesn't have time to save. My load takes also a bit of time on android.
public void SaveCubes()
{
foreach (Cube cube in parent8.GetComponentsInChildren<Cube>()) //around 160 loops
{
ES3.Save<int>("cube" + cube.id, cube.id);
}
}
foreach (Cube cube in cubeList.cubeToSpawnList)
{
if(ES3.KeyExists("cube" + cube.id))
{
//checks things comparing stuff with the id
}
}
Answer by xxmariofer · Sep 01, 2020 at 10:15 AM
the problem isnt with saving 160 variables thats instant is the way you are doing it using GetComponent 160 times in a frame, and why you have 1600 logs calls?
Thank you! It's from Easy save 3 log calls, you're right I never thought about it. I removed the call logs and it's a bit better now. For the GetComponent(), that's true I never thought about it reducing performance. Should I maybe put these objects in a List or and Array, and cycle through the list/array instead?
removing the logs and saving the object in an array will fix your performance problems for sure
Your answer
Follow this Question
Related Questions
Best way to export data and be able to import it in another PC. 0 Answers
How do i add coins in my Save Total Coin, everytime i collect more coins in the game? 0 Answers
Save and load player position in main scene 1 Answer
How To Save and Load player position using Serialization? 0 Answers
Saving and loading cube data 2 Answers