Option to make `AbstractMesh.isPickable` false by default

isPickable is true by default for all meshes. However, it would be really helpful for my project if it was false by default, and I could choose which were pickable.

It’s becoming hard to ensure that I’ve manually set isPickable false for all the MeshBuilder.CreateShape(), PointsCloudSystem, LinesMesh, GreasedLineMesh, and billboard meshes for UI containers and flash effects. Missing any could cause major game bugs.

I only want environment and player capsule meshes to be pickable (so ideally I could set true in only 2 places confidently instead of setting false in dozens of places and worry about missing some).

To satisfy backwards compatibility, could we have an boolean option somewhere to make isPickablefalse by default? If so, would you all have any ideas on the best place (e.g. global constant, Scene, Engine) for such an option?

Thank you all for your help :smile:

Could something like this work for you?

scene.onNewMeshAddedObservable.add((mesh) => {
    mesh.isPickable = false;
});

I think that adding a static for the default value of isPicking would also work:

class AbstractMesh {
    ...
    public static DefaultIsPickable = true;
    ...
    public isPickable = AbstractMesh.DefaultIsPickable;
1 Like

Thank you so much, Evgeni!

For the onNewMeshAddedObservablemethod, if a mesh that we want picked is removed ad re-added to the scene, would we have to set isPickable to true again?

I would love the static default approach! Please let me know if I should submit a PR with your approach :smile:

Not if you use Scene.addMesh, which is the function that triggers the onNewMeshAddedObservable observable.

Yes, please go ahead!

1 Like

Thank you so much for all your help, Evgeni! Just opened the PR! Add static `isPickable` to `AbstractMesh` by regnaio · Pull Request #18253 · BabylonJS/Babylon.js · GitHub

1 Like