multimesh set_instance_custom_data breaks when used in _process()

Godot Version

4.4

Question

I’m working on a game that needs to render a large number of meshes at once, so multimesh seemed like the perfect tool. Each of these meshes needs custom data to change their shader parameters, so I use multimesh::set_instance_custom_data to modify them. (and before anyone asks, yes “UseCustomData” is enabled)

It almost always works perfectly, however, if I set the data in a large set of meshes, and then set the data of another mesh inside of _process(), every other update will toggle between using the data before I made the large change and after I used the large change.

i.e.

  1. On startup, I make all meshes orange
  2. I call a function to make half the meshes green
  3. In process, I make a mesh the mouse is over blue
  4. Every other process step, the green meshes will flicker between green and orange (the blue mesh is always correctly blue)

This only happens when using _process. If I use _physics_process, then everything behaves as expected.
Is this a known issue with multimesh?

I can’t replicate this on a fresh project, so it might just be me doing something wrong on my end.
Definitely confused as I’ve no idea why _process vs _physics_process would have any effect on my logic here

If anyone knows why this might happen, I’d love to hear some ideas!

Other notes:

  • I am not calling set_instance_custom_data on the meshes that are flickering beyond that first function call (i.e. I have one call to change a large number of meshes, and then never touch the meshes again)
  • I have 393216 meshes
  • There are two multimesh objects in the scene (though only one is visible / updating at a time)
  • If I remove the _process() function, everything behaves as normal
  • All it takes to produce the issue is to make a single _process function that sets the first mesh’s data and nothing else

On that last note, here’s a sample _process() function that causes the issue:

func _process(delta: float) -> void:
	multimesh.set_instance_custom_data(0, Color())

Removing that function makes everything behave as normal - no idea why.