onPointerObservables fires too often

I want to use scene.onPointerObservable to detect mouse movements for a pressed mouse button, but the observer gets fired too often. I managed to reproduce the problem in this playground:

When you look at the console, you see the 2-4 lines with the same mouse coordinates. Why is this happening? Does anybody know a proper way to catch only one event per “new mouse coordinate”.

I think it inherits the browser event behavior. Every time you mouse is moved, this event is triggered. You can use debouncing if you want the event to be triggered less often. I use lodash.debounce to wrap the event handler functions that are computational expensive.

1 Like

Thanks for the hint. Would be great, if somehow the root cause could be avoided…:-/

The root cause cannot be avoided since it is browser implementation.
But with the help of simple debounce function there are no problems.
Example - https://playground.babylonjs.com/#76DBMU#4
The delay is 5 ms, seems it is OK to be “invisible” for users and fires only once.

3 Likes