How does babylon monitor long press events

e.g

          mesh.actionManager = new BABYLON.ActionManager(scene)
          mesh.actionManager.registerAction(
            new BABYLON.ExecuteCodeAction(
              {
                trigger: BABYLON.ActionManager.OnLongPressTrigger,
              },
              ()=>{}
            )
          )

It runs well on most touchscreen devices , but a small number of devices cannot be triggered.


:person_raising_hand: I wanted to know how this is monitored, so I found some source code

private _processPointerDown(pickResult: Nullable<PickingInfo>, evt: IPointerEvent): void {
        const scene = this._scene;
        if (pickResult?.pickedMesh) {
            this._pickedDownMesh = pickResult.pickedMesh;
            const actionManager = pickResult.pickedMesh._getActionManagerForTrigger();
            if (actionManager) {
               ......

                if (actionManager.hasSpecificTrigger(Constants.ACTION_OnLongPressTrigger)) {
                    window.setTimeout(() => {
                        const pickResult = scene.pick(
                            this._unTranslatedPointerX,
                            this._unTranslatedPointerY,
                            (mesh: AbstractMesh): boolean =>
                                <boolean>(
                                    (mesh.isPickable &&
                                        mesh.isVisible &&
                                        mesh.isReady() &&
                                        mesh.actionManager &&
                                        mesh.actionManager.hasSpecificTrigger(Constants.ACTION_OnLongPressTrigger) &&
                                        mesh === this._pickedDownMesh)
                                ),
                            false,
                            scene.cameraToUseForPointers
                        );

                        if (pickResult?.pickedMesh && actionManager) {
                            if (this._totalPointersPressed !== 0 && Date.now() - this._startingPointerTime > InputManager.LongPressDelay && !this._isPointerSwiping()) {
                                this._startingPointerTime = 0;
                                actionManager.processTrigger(Constants.ACTION_OnLongPressTrigger, ActionEvent.CreateNew(pickResult.pickedMesh, evt));
                            }
                        }
                    }, InputManager.LongPressDelay);
                }
            }
        } 
        ......
    }

So I thought it was using pointerDown to monitor long-press behavior


:person_raising_hand: And then I test on the ipad

As you can see from the video, the pointerDown event never fired when I clicked on the screen.

Events fired when clicked on the screen
most touchscreen devices pointerMove、pointerTap、pointerUp
small number of devices pointerMove、pointerTap、pointerUp

:person_raising_hand: So,two questions:
:triangular_flag_on_post:When i use actionManager,whitch event is used for test longPress,pointerDown or Other?
:triangular_flag_on_post:Why do both devices trigger the same event when touched, but only one of them triggers ActionManager‘s longpress

thanks !

cc @PolygonalSun

So, for the first question, the long press action should be done on the pointerdown. In the _onPointerDown function, the starting time is grabbed and then in _processPointerDown, there’s a timeout that’s started to check if any other pointers have been pressed in that time. If the starting time hasn’t been reset, a long press action is started. I believe that when there’s a button press (mouse-only), there’s a move after if the position differs from the last position but I’m not sure if that’s applicable to touch. Might be worth digging more into.

For the second question, that seems strange. I’d need to find a way to repro it so I could see what’s happening. For this video, did you set this in up a Playground and if so, could I get the link for it? I’d like to see what’s happening.

Try it on touchsreen devices.

Tap the screen continuously and you will find that pointerdown will only trigger the first time

Additional information:

TouchStart PointerDown
most touchscreen devices √ √
small number of devices × √

So events monitored with touch are not compatible with these few devices

@PolygonalSun @Evgeni_Popov

I am sorry that the data displayed on the interface misled me, from the data printed by the console, everything is normal