Random game lag

Godot Version

Godot 4.2.stable

My game lags heavily at around 1 second intervals and randomly goes back to normal. Also there is a big difference between frame time and physics frame time, is this normal?

This is definetly not normal lol
From the large physics frame time id say the problem lies there

Maybe check for bodies hopping around from minimal bounce in a confined space? That can take up a lot of frametime
How many bodies do you have?
Do they have sleeping enabled?
Hows your _physics_process(_d) look?
Is this a 2D or 3D game?
With 3D are you rendering the entire world at once while loading all models ,including those in the distance with full resolution?
Do you have any weird timers running?

I encountered sth similar in a humongous 2D world with interactive entity behaviour that was calculated in full over ca 1000x screensize, so my first instinct would be sth like that.

A bit more information would help haha


Thanks for the answer! Its a top down 2D vampire survivors-ish game. The world is just a medium sized arena and im spawning max 50 enemies (CharacterBody2D) so I doubt that the issue is the number of enemies. After a lot of brainstorming I ran the game on another device and a big chunk of the lag is gone, maybe I need to update some drivers or something.
Should I aim to match the frame time to the physics frame time? Or them being so far apart is normal. Honestly im so confused :smile:

1 Like

Yeah a driver issue would do that to you haha

Those times being far apart is rather normal, the concerning thing was periodic instead of constant lag

At this scale of game with any reasonable hardware (4 cores, an actual graphics card) there should be absolutely no lag at all, so if it still continues, your code might be funky :wink:

Switched to my laptop and optimised the enemy code a bunch and the lag seems to be gone, so yeah, drivers do be sneaky :pensive:
Thanks for the tips regardless!

1 Like