Adding a new node in a scene with hundreds of nodes causes lag in editor

Godot Version

4.2.2 stable

Question

( This takes place in 3D)

Upon adding a new node to my scene with hundreds of other nodes in it, the scene lags. This lag increases the more nodes there are in the scene.

It does not seem to matter which node is added, having a large majority of my nodes be just Node3Ds and adding a Node3D does not appear different from having the majority be MeshInstance3Ds ( with 200+ tri meshes) and adding another MeshInstance3D.

I’m making a paint brush plugin to paint foliage, and this is impacting the usability significantly. It only lags upon adding the child node, not instantiating it, and not while idling.

I do not feel the code would be important as the problem lies with adding a node into the scene, even through the editors “Add Child Node” in the top left. Feel free to ask if you believe it would give you a better picture.

Any help is appreciated (especially if it is turning on the profiler while in the editor, that would immensely help with debugging).

And if this is just a limitation of the engine, that would REALLY suck.

Yes adding and removing from the scene tree is quite expensive. For your use case look into GPU instancing, the MultiMeshInstance3D provided by Godot does such instancing.

As I stated in the post, it doesn’t matter what type the node is. Also I don’t think I can use multimesh instances in my situation since the paint brush stroke doesn’t always cover an entire mesh.

Not sure that’s a problem with MultiMeshInstance3D. What do you mean cover an entire mesh?

You would add one MultiMeshInstance node and populate it with as many mesh transforms as you need, no other children or scene tree manipulation.

Proton Scatter uses this node (or instancing in general) as it’s backbone for example.

When you use a MultiMeshInstanced3D, it has to populate a mesh, and covers that entire mesh in whatever other mesh you select to be instanced. If I was to use my paint brush and add a MultiMeshInstance3D to every mesh the brush fell on, it would cover the mesh in its entirety rather than in the localized area of the brush.

This is not true, I think you are referring to the in-editor tool that helps scatter over a mesh, but it’s not the only way to use a MultiMeshInstance3D.

You would reserve/resize the MultiMesh’s instance_count to a high number. As you paint update transforms with set_instance_transform to your paintbrush location (maybe with some jiggle), and add to the visible_instance_count until you need to reserve more instances with a higher instance_count

Wow, turns out I overlooked MultiMeshInstance3D simply because I thought I understood it when I did not. Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.