# Skip Valid Mesh Evaluation for Scene.PickWithRay?

**URL:** <https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274>\
**Category:** Questions\
**Created:** [March 19, 2025, 6:15pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274 "2025-03-19T18:15:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 19, 2025, 6:15pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/1 "2025-03-19T18:15:48Z")

</div>

My understanding of how the pick with ray might be off so correct me if I am wrong.

But I am under the impression before the picking predicate is ran, that a “valid” meshes array is built that the picking predicate has those entries looped through it?

Or is it that the predicate is what creates the valid meshes array to run the pick against?

I figured it was the first, and so continuing on with that thought is there a way to fire a pick manually against a specific mesh instead of the entire scene? Or a manually array of valid meshes? I have a specific setup where I know the exact mesh that needs to have the ray ran against and currently I’m using the predicate to filter, but feel like that is iterating through all active meshes in the scene and I could get more performance if only ran against the specific meshes I need.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [March 19, 2025, 6:21pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/2 "2025-03-19T18:21:00Z")

</div>

Your assumption is correct:

Extract:

```auto
    for (let meshIndex = 0; meshIndex < scene.meshes.length; meshIndex++) {
        const mesh = scene.meshes[meshIndex];

        if (predicate) {
            if (!predicate(mesh, -1)) {
                continue;
            }
        } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
            continue;
        }

```

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 19, 2025, 6:25pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/3 "2025-03-19T18:25:33Z")

</div>

hmmm so if I want to do a “filtered” one then I should copy this method and reshape it to my needs?

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 19, 2025, 6:54pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/4 "2025-03-19T18:54:17Z")

</div>

If I know the exact mesh can I just use this method:

> <https://github.com/BabylonJS/Babylon.js/blob/7a71cf0849d279bbbb2fdc1b1da942d7d56e2841/packages/dev/core/src/Culling/ray.core.ts#L819>

_UPDATE_  
Kinda basically had to just do the chain of scene.pickWithRay but override the InteralPick to use a new array argument for meshes.

And yes it is way way faster in large scenes, where I have specific meshes I want to target.

---

<div class="post-metadata">

**Author:** ![Joe\_Kerr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/joe_kerr/32/39017_2.png) [@Joe\_Kerr](https://forum.babylonjs.com/u/Joe_Kerr)\
**Post date:** [March 20, 2025, 8:44am UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/5 "2025-03-20T08:44:36Z")

</div>

> [@Pryme8](#):
>
> I know the exact mesh that needs to have the ray ran against

Does this work, too: [Babylon.js docs](https://doc.babylonjs.com/typedoc/classes/BABYLON.Ray#intersectsmesh)?

Wouldnt need to override classes then.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 20, 2025, 2:56pm UTC](https://forum.babylonjs.com/t/skip-valid-mesh-evaluation-for-scene-pickwithray/57274/6 "2025-03-20T14:56:45Z")

</div>

That actually would work yes I’d have to make a method to loop through the ones I want but yeah. Looks like it would be about the same results maybe.

Good call out.

I ended up not needed to override anything just hijacked the chain and changed the one method.

But this solution might be easier I’ll take a look thank you.
