Updating MultiMesh instance colors in _process()?

Godot Version

4.3.stable

Question

I currently have a MultiMeshInstance2D set up that accepts color as the instance data, and I know it works if I set the instance color upon the MultiMeshes creation or in _ready().

However, if I try setting instance data in the _process() function, nothing visually changes, even if i do a queue_redraw() right after. Is updating MultiMesh instance data in the render step not something that you’re supposed to do?

Example Psuedocode:

(Not my actual code, just showing what I’m trying to do and the fact that it doesn’t work.)

## Given that $MM is a MultiMeshInstance2D
## and $MM.multimesh.use_colors == true...

func _ready():
	# works, color is set to red
	$MM.multimesh.set_instance_color(0, Color.RED)
	
	# also works, color is set to blue
	$MM.multimesh.set_instance_color(0, Color.BLUE)
	
func _process(_delta : float):
	# doesn't seem to work, unless I'm doing this wrong?
	# in this example, instance 0 would still visually be blue.
	$MM.multimesh.set_instance_color(0, Color.GREEN)
	
	# neither of these do anything to resolve the issue
	queue_redraw()
	$MM.queue_redraw()
shader_type canvas_item;

varying vec3 i_color;

void vertex() {
	i_color = COLOR.rgb;
}
void fragment() {
	COLOR.rgb = texture(TEXTURE, UV).rgb * i_color.rgb);
}

Many thanks to whoever can help me figure this out!

MultiMesh.set_instance_color() sends the new Color directly to the RenderingServer instance.

EDIT

I just tested it in Godot 4.4 master and it works fine when you do a single call to the set_instance_transform_2d() function as well, as that triggers a changed signal update of the multimesh that the instance color function seem to be missing.

We discussed a bit in the dev chat, this does look like a bug, please report it here GitHub · Where software is built

Don’t forget to attach a minmal reproduction project, otherwise we can’t really fix it.

1 Like