Unexpected physics frame drops with drawn objects leaks

Godot Version

4.5

Question

I’m building a simple game containing an agent that destroys objects on the map. I have around 30 boxes with simple collisions (Node3D with child StaticBody3D/CollisionShape3D:Box), agent (CharacterBody3D/CollisionShape3D: capsule), ground (StaticBody3D/CollisionShape3D: Box). Agent uses different weapons (physics-based detection): projectiles, explosions, and rays. Each object has a child POI with tags, HP, etc - the agent’s logic revolves around POIs.

I encountered strange behavior:

  • Total Objects Drawn is increasing constantly, with fewer and fewer objects visible on the scene
  • Physics Process takes more and more time, from 3ms at the beginning, when the scene is most complicated, to over 100ms at the end, when all boxes are destroyed

Monitors show: steady Nodes, Objects, and Resources count, no Orphan Nodes, steady (decreasing) Total Draw Calls. The remote scene shows everything as expected - new projectiles or explosions created and disappearing, nothing strange. Profiler shows that the physics tick is longer and longer, but no calls are associated with this (must be something internal). I tried using physics on the main and separate threads. I even wrote my own profiler to check all the code inside _physics_process and everywhere else - no luck. I don’t create or clone materials or meshes; everything is super simple. I count all the objects by myself and cannot detect any leaks - I suspect a strange leak with something invisible with physics is constantly being added to the scene.

I’ll appreciate any ideas on how to tackle this problem, thanks!

How are you spawning and creating the projectiles, explosions, rays?

Do they have a visual element to them? If yes, are you freeing them using Node.queue_free() when they aren’t needed?

How are you checking the collision?

Are you using any server like PhysicsServer3D or RenderingServer directly? If yes, are you freeing the created objects RIDs when necessary?

Try posting more information, scene structure, source code,…

Hi all,

Thanks for the replay.

I found the culprit, it’s my console window showing the various logs in different channels. I’ve been pushing the new messages to the console in the _physics_process, and the console immediately tried to show the new messages in the control (RichTextLabel with BBCode). When I moved updating the label into independent _process in the console - all the problems vanished.

What I learned:

  • never update UI controls in the _physics_process
  • RichTextLabel with BBCode is super slow. Showing more than 500 lines is killing the framerate

Cheers!