Instancing with StaticBody & CollisionShape is very slow

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cakemonitor

Hi,

I’m creating a voxel-based game with procedurally generates rooms. I’ve created a ‘voxel-no-collision’ scene which just contains a single MeshInstance node, and elsewhere a ‘room generator’ script instances this scene and then uses a SurfaceTool to build the appropriate cube faces. Without any collision involved everything runs at a reasonable speed. However, when I have the room generator instance a different ‘voxel’ scene which is identical except it also contains a StaticBody and CollisionShape (which has a default BoxShape and a scale of 0.5, 0.5, 0.5) the level generation becomes very very slow.

As a point of reference, I instantiated a 20x20x20 grid of cubes without collision and it takes on average about 125ms to complete, but with collision it takes on average 5 seconds (i.e. with collision it is 4,000% slower!)

For comparison, I set up the same process in Unity (spawning a 20x20x20 grid of Cube Prefabs - both with and without a BoxCollider). Without collision involved the instancing speed was very similar to Godot (around 125ms), however the addition of a BoxCollider to the prefab had a far smaller impact. The total time to instance all 8,000 ‘cubes with collision’ increased to just 200ms - so only 60% slower which is a lot better that the 4,000% slow-down that I’m seeing in Godot.

Could anyone please explain the cause of the delay that I’m seeing, and let me know if there is a different approach that I could take in Godot to achieve similar speeds?

Thanks in advance.

:bust_in_silhouette: Reply From: Calinou

This is a known issue since the migration to Bullet, see this GitHub issue. Try switching to Godot physics in the Project Settings and see if performance improves.

Thanks! It’s about 5 times faster with Godot Physics, but I get other errors and my character no longer moves. But I made a few optimisations in terms of how many colliders I need and I can probably design around other performance issues for now, so I’ll stick with Bullet.

cakemonitor | 2019-02-03 22:25