BABYLON.GUI and simulatePointerDown

Can simulatePointerDown work with BABYLON.GUI? Is there an alternative?

edit: #6; added attempt at a fake click; didn’t work
edit 2: #8; return 0 if not locked
edit 3: re-worded question
edit 4-5: #12; rewrote MouseEvent trigger, made locking occur on click instead of instantly
edit 6: #13; removed target and path from MouseEvent
edit 7: #14; removed error, added simulatePointerDown
edit 8: linked a(n old) git issue
edit 9: #19; set scene.pointerX, scene.pointerY, and fiddled with the maths

There seems to be a code error when trying to fake the click (Game is not defined). Would be great to get it working so we can test it together with you.
Nonetheless - we internally use pointer events. pointerdown, pointerup and pointermove . We also provide simulate functions, like this - Scene | Babylon.js Documentation , though a native browser event should work just the same. includes simulatePointerDown and the removal of the offending code; is it documented to work with BABYLON.GUI?

There are a few things that are wrong in the way the code is structured. First, you already have a mouse, and you relay on the mouse/pointer events to generate another mouse/pointer event. Why is that needed?

Having said that, if you still want to get that to work, you will need to set the scene’s pointerX and pointerY correctly, and simply trigger simulatePointerDown with empty objects. There is no reason to run scene.pick, unless you need the picking result somewhere along the way.


  • simulate pointer events is working with GUI elements
  • simulate pointer events extends the pointer event data sent to the function, and uses scene.pointerX and scene.pointerY to simulate the click at this specific point
    Don’t simulate pointer events using the mouse, because that would create awkward/unexpected results.
1 Like

Got it mostly working; line 133 is where I’m having the issue.
1.9 works
1.958620689 works
1.95862069 doesn’t work
2.0 doesn’t work
2.03827751196 doesn’t work
2.03827751197 works

There shouldn’t be any issue with that. It seems like you have callstack issues :slight_smile:

This is the unexpected behavior I was talking about when I mentioned simulating events inside real events

I’m not getting this error on #19

edit: scratch that, got it

when changing it to 2

1 Like

Added a condition that flips during click to mitigate the recursion issue :v

And I realized why I couldn’t pick at the very center of the cursor: it’s trying to pick itself. I’d need to create a cursor AROUND the point that picks :v heck

1 Like