Is SurfaceTool thread-safe in Godot 4?

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


I’m working on a voxel-based procedural generation system for my game, and while the chunk generation is on a separate thread, the callback to render is also executed by the same separate thread. From my perspective there doesn’t seem to be anything wrong with the generation, but maybe I’ve just been this lucky.

Is SurfaceTool thread-safe in Godot 4?
If it isn’t what should I expect to happen?

:bust_in_silhouette: Reply From: kyuth

SurfaceTool should be thread safe in Godot 4 (I used it myself in a separate thread in Godot 3 and it worked fine, should work in 4 too) but as a general rule anything related to rendering and scene tree is not, see

So you probably should do the chunk generation in a separate thread but add generated MeshInstances to scenetree in the main thread.