Bug on Lazy picking with SpriteManager

Hello,

We encounter a bug related to the recently added feature of LazyPicking in v5.29.0 and its interaction with sprites.

Here is a minimal playground that reproduce the problem: https://playground.babylonjs.com/#EVYLLB#8

While setting constantlyUpdateMeshUnderPointer = true on a scene, we expect to be able to constantly get picking info on meshes when attaching a callback to the onPointerObservable of the scene. It does work until we add a SpriteManager to the scene.

When a SpriteManger is added to the scene, picking info contains null information when hovering meshes and while mouse is down. It gets information only on mouse click events.

We suspect that it comes from the recently added feature of lazy picking, where the picking info is not necessarily filled automatically in scene.inputManager.ts::_onPointerMove() (line 794) but rather at the call of the getter.

Later in the InputManager._processPointerMove() method, a for loop iterates though elements only related to sprites. If there is at least one SpriteManager, The loop will fill information about picking info preventing a future call to the getter to compute new information. Sadly, this loop fill null information to the picking info :frowning:.

Hopefully we found a workaround to the problem but it consists on suppressing the lazy picking. We basically add a DoNothingAction to the scene on hover:

scene.actionManager = new BABYLON.ActionManager(scene);
scene.actionManager
  .registerAction(new BABYLON.DoNothingAction(
                  BABYLON.ActionManager.OnPointerOverTrigger));
// Note that we use a mesh trigger on the scene ...

That way, at scene.inputManager.ts::_onPointerMove() (line 794), there is an action registered and we force the picking.

Finally we think that the lazy picking does not really work with the interaction of sprites. I personally don’t know the code well enough to propose a fix for that :frowning:

That’s all for the post,
Thanks for the reading,
Have a good day !

Welcome aboard!

Let’s cc @PolygonalSun who is the master of inputs.

Lemme take a look and see what’s going on

Okay, so I’ve taken a look and here’s what I’ve found. By default, with Lazy Picking, the picking will only happen when there’s a need for the information. For some instances, like having an active ActionManager or SpriteManager, picking can’t exactly be done lazily because that information is used with each event. It shouldn’t use Lazy Picking with the SpriteManager but it looks like the logic is flawed. The fix is easy enough so I’ll try to have something in PR soon. I’ll update when the PR is live.

1 Like

PR is live: InputManager: Move-based Picking not working with SpriteManager and specific flag by PolygonalSun · Pull Request #13982 · BabylonJS/Babylon.js (github.com)

3 Likes

PR is merged

Wow, that was quick !!

Thanks a lot for the fix