Set InstancedMesh userData

Hello

Sorry I’ve tried figuring this out myself but not got anywhere with it.

I’m trying to pass userData into instances within an instancedMesh. I appreciate each instance will have it’s own instanceId but I’d like to pass in other details to the individual instances if possible.

In this link I’ve set up a grid of boxes. I see from the docs that userData is a property on an Object3D, which I’m using in my instancedMesh (denoted as temp). So on lines 17-19 I’m trying to pass in some data to the userData property. On line 38, within the onClick method I’m trying to console out what I believe is the intersected object so that I can see its userData, however it’s coming out as empty.

Is this possible to do?

Any help would be greatly appreciated!

Cheers

Steve

Just giving this a little bump…

.userData is attached to an Object3D instance, like InstancedMesh in this case. So there is no .userData property for each instance individually – the InstancedMesh represents all of the instances.

Instead what you might do is to store an array of the data you want, indexed by the instanceID. Then when you get a click event you can look up the data in that array.

1 Like

Good idea, thanks for the clarification Don :+1: