Highlighting an instance in InstancedMesh

I’m using InstancedMesh for my app. I would like to highlight an instance when picked using raycast. I see that a raycast intersect returns the instanceId. There is an example - webgl_instancing_raycast.html where this is used to interactively trigger a rotation for the picked sphere. How would I apply this approach to highlight/unhighlight an instance. Note: I am using the approach of examples/webgl_instancing_modified.html that adds an instanceColor attribute to a pre-existing shader. It all works fine. I just need to add highlighting.

this is a react example but the code that is deciding on the highlight is the same: https://codesandbox.io/s/r3f-instanced-colors-8fo01?file=/src/index.js:1297-1538

essentially you take instanceId and compare it against the previous one, then you call geometry.attributes.color.needsUpdate = true

1 Like

A duplication of the question!

There is the solution of @prisoner849 from the night. :+1:

Sorry about the dupe guys. I thought I had mistakenly discard this.

See my follow up question on the duplicate post. Cheers.