Picking Isn't Working When Using Asset Containers

Sorry that I can’t reproduce in a Playground, but since moving meshes into Asset Containers, the mesh picking isn’t working. What’s odd is that if I use the Ray Helper, I can clearly see the intersection with the mesh:

However, the PickInfo is always null:

The code I’m using is a variety of examples, such as this one:

  var ray = scene.createPickingRay(
      scene.pointerX,
      scene.pointerY,
      Matrix.Identity(),
      activeCamera,
      false,
    );
    let rayHelper = new RayHelper(ray);
    rayHelper.show(scene, Color3.Red());

    var pickResult = scene.pick(scene.pointerX, scene.pointerY);

    var hit = scene.pickWithRay(
      ray,
      mesh => {
        console.log('Mesh', mesh.id);
        return mesh.isEnabled();
      },
      true,
    );

    console.log('debug', pickResult, hit);

Any clues?

Must be something in your code, normal scene picking still works for me

2 Likes

This will unfortunately be hard to troubleshoot without more info :frowning:

Yeah, I think, based on the example from aWeirdo, that there’s a difference when using the LoadAssetContainer method vs adding meshes to multiple containers in a loop. My suspicion is that the root mesh (not being added to the container) had some kind of offset so that when adding the meshes back to the scene, their matrices are not being correctly passed to the picker. Hence, the RayHelper shows the ray intersecting the meshes but the picker thinks they are not.

However, we’ve found a workaround to keep us moving.

1 Like

I faced with similar problem. And it had been solved with Scene | Babylon.js Documentation

scene.onReadyObservable.addOnce(() => {
  // run your code here like scene.pickWithRay()
});

Seems like you can’t use picking for mesh which not ready(for me it was loading texture for MeshBuilder.CreateGroundFromHeightMap)

I tried this but no luck. It sounded promising!