For a long time, my game has been stuttering at seemingly random intervals. Recently, I was able to find the cause of this stuttering using Godot's profiler. It turns out that my game was experiencing occasional lag spikes, where a single frame would take up to 200 milliseconds, while playing. However, according to the profiler, Idle Time is taking up 99% of each frame even when there is a massive lag spike, with all other functions only taking up a fraction of a percent. Does anyone know what causes Idle Time to increase and decrease.
Stuttering due to Idle Time
I ran some tests and found that this problem persists no matter which scene I'm currently on. On top of this, it seems to only happen once, 30 seconds after I start my project. So far, I haven't been able to find any instances of stuttering after this. I think I might have something to do with Godot loading asset. So does anyone know how see the actions Godot preforms in the background.
Could it be shader compilation?
I had a similar issue with idle time a long time ago, but I don't remember exactly how I solved it or if I solved it at all :sweat_smile:
I think it was caused by instancing grenades in the FPS, and like how you described, it only happened once. I think the solution was to place a object using the same material in the scene off camera, and then delete it after a frame or two, which forces the shader to compile when loading the scene and that fixed it.
We need more information to be able to help.
- Which Godot version are you using?
- Which operating system are you on? If on Linux, which window manager are you using, and do you have compositing enabled?
- Are you using GLES3 or GLES2 rendering backend in your project?
- Is V-Sync enabled in the Project Settings?
Also, it's possible that this will be fixed by frame delta smoothing once it's merged.
Right now I'm using version 3.2.3 on windows I'm using GLES3 right now and V-Sync in enabled
Hopefully this helps someone else....
I was having a similar issue. Idle time spiked in the profiler to like 400+ ms at a very odd time. No indication in the profiler as to which script might be causing this.
Turns out the culprit was calling .hide()
on a directional light at runtime. I tested this with V-Sync both on and off, same result. And I also tested this trying to call .hide()
on other things, but nothing else spiked quite like the light did. I can only speculate as to why, but maybe it has something to do with shadows / light baking?
Anyway, in my case I just fixed it by reducing the energy to 0.