Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Kaikoura on April 29, 2023, 11:23:07 AM

Title: freeze during save [SOLVED]
Post by: Kaikoura on April 29, 2023, 11:23:07 AM
hey, I´m using EasySave3 and the save action.
When I save something (even just an Int) the screen freezes for like 0,2 sec.

I want for example open a chest, change the array of items in it and then close it and save the array. But the short lag is quite annoying.

Is there a good way in playmaker to save without this kind of freeze?
Thanks!
Title: Re: freeze during save
Post by: Christoph on April 30, 2023, 01:04:50 AM
It shouldn’t do that. What’s your setup? Can you show screenshots of FSM states and actions? Is this on device or in unity editor? And what playmaker/unity version are you using?
Title: Re: freeze during save
Post by: Kaikoura on May 01, 2023, 04:27:45 AM
hey,

I´m using the LTS 2021.3.17f1 Version of Unity.
It happens in Playmode and also if I build and run the game.
Loading causes no lag, just saving.

Here is a little example setup:

(https://i.imgur.com/0OqjR28.png)

I`m in the start state. In the next state, I save the testInt with the easySave3 save action

(https://i.imgur.com/UWrfZSj.png)

if I do, there is a short freeze, like you can see here in the profiler:

(https://i.imgur.com/adPNOBY.png)

(https://i.imgur.com/fOR6h7g.png)

Otherwise the game runs smooth as butter.

Title: Re: freeze during save
Post by: djaydino on May 01, 2023, 08:22:42 AM
Hi.
Save is writing to a file and will always give lag.

What you can do is Save when loading to different scenes / Goin to main menu / Quitting game.
Title: Re: freeze during save
Post by: Christoph on May 01, 2023, 09:17:33 AM
Damn. That’s interesting. I must be saving then in the exact precise moments where lag is not visible. I mean yes I don’t do it during gameplay for example. Only at level end, or after character unlock, new level created etc. it always happens when something “finished“ so to say. But I still have Gui tweens happen and stuff. And they don’t lag. Is it happening always or only the first time you’re saving?
Title: Re: freeze during save
Post by: Kaikoura on May 01, 2023, 12:09:35 PM
hey, thanks, 
yes it always lags.

Doing it like you would definately be a solution.
I´m just surprised that it seems to be so difficult to safe during runtime without any lag.

There is something called coroutines which allows you to spread tasks across several frames. There is even a playmaker action for it (which I don´t know how to use). Maybe this could be a solution?
Title: Re: freeze during save
Post by: Christoph on May 01, 2023, 01:06:57 PM
So I checked because I thought that this just couldn't be...

and indeed I have save actions being used all the time. Even when gameplay is used. For example I have a timer setup for a special IAP at discount. Every 5 seconds I'm saving this new float value in case the user leaves the app. Probably not best to do it like this. But it definitely doesn't cause any lag. Not in editor nor on device, tested even on mid range performance Android like a Xiaomi Mi 11 Lite 5G and all good.

So it must be something else that is causing this. What devices have you tested this on? Do you have enough hard drive space available?

Edit: coroutine action just calls a coroutine method from a script. Nothing more. So no, not helpful here.
Title: Re: freeze during save
Post by: djaydino on May 01, 2023, 05:02:19 PM
Hi.
Maybe it depends on how big you save file is becoming as in the early stage of our game we had no noticeable issues yet.
But after more things got saved in it, it started to lag more and more.

Most games actually save during loading times/ menu's etc.
Title: Re: freeze during save
Post by: Christoph on May 02, 2023, 10:40:11 AM
In your profiler, can you open up the detail view of what is causing the spike? And how are you triggering the next event to get to the next state?
Title: Re: freeze during save
Post by: Kaikoura on May 02, 2023, 06:52:22 PM
hey

@djaydino
it probably doesn´t have to do with the size of the save file, as in the example I made earlier I´m just saving a simple Int.
Saving during load or in menus would be a suboptimal solution for my project, because the player is a lot in one scene in which I want to save and load in.

@Christoph
These are my device infos:

Processor   AMD Ryzen 7 1700X Eight-Core Processor            3.40 GHz
Installed RAM   16.0 GB
System type   64-bit operating system, x64-based processor

and I have about 700 gigabyte left on hard drive...

I honestly don´t think it has something to do with my hardware, as the game runs smoothly most of the time with like 80 fps until I save.
----
ok, I just tested the save action on an older project, and it runs smooth, like you described, even if i spam it.
In both cases I just alt clicked the transition to fire, I tried different approaches though and this is probably not the problem.
So it has something to to with my setup, like some packages or the render pipeline(I use URP).

in the profiler I can see that a few things are waiting( I´m not very good at understanding these terms yet):

(https://i.imgur.com/PSBVQFM.png)

(https://i.imgur.com/744X0de.png)

I´m not quite sure what is waiting for the action to finish or what exactly is causing the lag itself.






Title: Re: freeze during save
Post by: djaydino on May 03, 2023, 11:50:24 AM
Hi.
Its look like its an editor loop.

to profile more accurate, you need to test with a profiler build.

Maybe this unity thread can help :
https://forum.unity.com/threads/semaphore-waitforsignal-causing-performance-issues.824580/
Title: Re: freeze during save
Post by: Christoph on May 03, 2023, 05:25:17 PM
You said it happens on device too, but in case it's does not,... do you have playmaker open when you play in editor?
Title: Re: freeze during save
Post by: Kaikoura on May 04, 2023, 12:43:46 PM
hey,

thanks djaydino, I read the thread but sadly couldn´t find a solution for my problem.

Hey, yes I had it open, as I was starting the transitions manually.

I updated Unity to a newer version and I get different information by the profiler now.
Apparently the game slows down because of Garbage collection.

This is how it looks before I save:
(https://i.imgur.com/cnWxwzJ.png)

and this is during the save action:
(https://i.imgur.com/DKzgHzI.png)

so the lag is produced by PlayMakerFSM.Update()

I try to read into this and understand why it could happen but maybe you know anything?
Thanks for the help so far regardeless :)


Title: Re: freeze during save
Post by: djaydino on May 04, 2023, 01:14:53 PM
Hi.
If you are in unity 2019.3 or above.
in project settings / Player / Other
Turn on 'Use incremental GC'
Title: Re: freeze during save
Post by: Christoph on May 05, 2023, 12:54:45 AM
What are you running in update? This is normally an action set to “every frame”.
Title: Re: freeze during save
Post by: djaydino on May 05, 2023, 10:39:04 AM
Hi.
To get more info you should try a build and use deep profiling as many actions are using PlaymakerFsm.Update.
Title: Re: freeze during save
Post by: Kaikoura on May 05, 2023, 12:22:31 PM
hey,

I had incremental GC turned on already but it didn´t change anything.

But good news:
I deleted all old save files and it works now. I don´t know why, one of the save files somehow slowed everything down when saving.

I just opened Tools -> easySave3 ->clearPersistentDataPath

such a simple solution!

Thanks a lot still for helping me out, I learned a few things :)

Cheers

Kaikoura
Title: Re: freeze during save [SOLVED]
Post by: Christoph on May 05, 2023, 05:49:08 PM
Awesome! Glad it got solved!
Title: Re: freeze during save [SOLVED]
Post by: djaydino on May 05, 2023, 08:05:41 PM
You might want to check if a Save has encryption enabled (or disabled if you are using encryption)
It can damage the save file if one has a different setting, which might be the reason that you get the lag spikes (but it should also give an error)

make sure that 'error pause' is always on in the console window, so that the game will pause if you get an error.
Title: Re: freeze during save [SOLVED]
Post by: Kaikoura on May 06, 2023, 04:43:46 AM
thanks djaydino,
 I will check these settings👍