CSG Nodes Slowing Performance

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

I’m creating a city procedurally, for that I’m using CSG nodes in code to generate the houses, but right after I added the houses to the city, the game took forever to load.

I wanna know witch are the methods available to optimize the performance on my case.

Also, I heard that CSG nodes are just for prototyping because of the performance weight related to it, is that true?

why are you using CSG nodes? Why dont you use simple mesh instances?
You know, CSG nodes are for boolean operations on meshes!?

klaas | 2021-07-20 19:12

Hi, I first tried with MeshInstances, but I had problems with faces sharing the same space, now I’m using CSG nodes with union and subtract operations, witch makes a lot easier to program

JayJay99 | 2021-07-20 22:27

CSGs being a boolean operator means that every single frame they are updated (i.e, moved or in your case added to the scene), they all have to perform a calculation on how to intersect their geometry. The more you have, the worse it gets until your game won’t run anymore. In general, you can estimate their performance hit by updating them in the editor (because they lag the editor too).

But CSGs are more intended to be fully modelled (and calculated) in the editor — for now at least, there’s no way to fix that terrible performance aspect at runtime, as they weren’t designed with that use in mind.

You could maybe create them as a scene and instance the scene…? I’m not sure if that would still have a performance hit or not. And in using MeshInstance, maybe you could model with quads in places where you have geometry overlaps (so, more work but then you won’t have overlaps).

Yuminous | 2021-07-21 00:17

Make sure to use separate node trees for CSG operations. Don’t cram all CSG nodes under a single CSG node; only use boolean operations where you actually need them

Calinou | 2021-07-21 01:18

:bust_in_silhouette: Reply From: Yuminous

So, basically : with CSGs —

CSGs At Work
This is their expected behaviour.

CSGs unique feature is to add or subtract together and it’s why they are known as boolean operators. A CSG Combiner takes a group of CSG meshes and tries to make a singular mesh out of all of them.

Boolean Operations

It potentially has attractive video memory benefits, but if every single mesh within it has to be (re)calculated together in a single frame, your game will slow tremendously.

“Is this mesh in that mesh? If yes, then make a mesh-sized hole right there — in all 100 or so meshes.” (now try and figure out how many vertexes it should have).

CSG meshes ≠ Bad

I should be clear that the issue with CSGs is predominately with the way they typically degrade performance. The meshes themselves aren’t baddies:

Speedy CSG
In this case they’re acting no different to MeshInstances and they’re as fast or faster when spawning them from code. But it’s just not the same story if you opt to utilise their design feature. So the question is do you really need them in your project?


– Do you really need boolean operations? (to make chamfers, cutouts, holes, etc.)

Lots of Boolean Operations
– Do you need to group all your meshes under one CSG Combiner? (use multiple)

Separate Combiners don't affect each other
– It is super necessary for your project to script individual meshes at runtime?
(perhaps you could instances scenes of procedurally-ready house sections)

Instancing Scenes through Code
– Finally, could you achieve the same using a premade 3D model (Blender)?

Blender can be easy——ish...

I hope that it helps in some way!
Good luck!

Thanks! I will think this trough, I’m considering to use pre-made chunks and add then to a GridMap

JayJay99 | 2021-07-22 03:41