Return clicked object in scene from `onPointerDown`?

I’m wondering if there’s a way I can return a mesh or any value from a onPointerDown() event so I can check to see if it’s a “clickable” option or not in my game.
Would I have to ray to the object?

Hey! I guess you can do the job with “Picking Collisions”
(Picking Collisions - Babylon.js Documentation)

I modified your example and hope thats what you wanted :upside_down_face::

1 Like

the version of wulf11 is working, but i guess i have another solution which is a little easier and different in use. You also get the pointer event (evt), which you could use for other things as well if needed. But anyways it’s up to you which way you want to go :slight_smile:

1 Like

Oh I hope that I understand correctly, that onPointerDown is allready returning a PickingInfo and so my code is kinda redundant? Or are there other differences? Just interested :sweat_smile:

As you can see here: Scene - Babylon.js Documentation

onPointerDown is already returning PickInfo, so you dont need to manually set it. I guess it is in fact redundant, as both versions contain the same informations. As i unterstand there are no further differences.

1 Like

@i73 just for your information. This is only working for meshes which have

mesh.isPickable = true

enabled (which is default). If you want to exclude meshes, so that they are not pickable, just set this parameter to false.

Thanks guys, I was overlooking the fact the callbacks this.scene.onPointerDown = (evt, pickResult) => { this works for my case!

1 Like