playMaker

Author Topic: freeze during save [SOLVED]  (Read 3477 times)

Kaikoura

  • Playmaker Newbie
  • *
  • Posts: 23
freeze during save [SOLVED]
« 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!
« Last Edit: May 05, 2023, 12:30:29 PM by Kaikoura »

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #1 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?

Kaikoura

  • Playmaker Newbie
  • *
  • Posts: 23
Re: freeze during save
« Reply #2 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:



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



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





Otherwise the game runs smooth as butter.

« Last Edit: May 01, 2023, 04:35:11 AM by Kaikoura »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: freeze during save
« Reply #3 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.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #4 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?

Kaikoura

  • Playmaker Newbie
  • *
  • Posts: 23
Re: freeze during save
« Reply #5 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?

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #6 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.
« Last Edit: May 01, 2023, 01:37:13 PM by Christoph »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: freeze during save
« Reply #7 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.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #8 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?

Kaikoura

  • Playmaker Newbie
  • *
  • Posts: 23
Re: freeze during save
« Reply #9 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):





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






« Last Edit: May 02, 2023, 07:00:05 PM by Kaikoura »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: freeze during save
« Reply #10 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/

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #11 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?

Kaikoura

  • Playmaker Newbie
  • *
  • Posts: 23
Re: freeze during save
« Reply #12 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:


and this is during the save action:


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 :)



djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: freeze during save
« Reply #13 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'

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 256
Re: freeze during save
« Reply #14 on: May 05, 2023, 12:54:45 AM »
What are you running in update? This is normally an action set to “every frame”.