Hi.
I understand this might be unconventional, but is there a way to force trigger click event on the GUI element programmatically?
Hi.
I understand this might be unconventional, but is there a way to force trigger click event on the GUI element programmatically?
Would it be unacceptable to do something like this?
const handleClick = () => console.log('clicked')
rect1.onPointerClickObservable.add(handleClick);
// run programatically
handleClick()
If for some reason that wouldnāt work, maybe you can get the 2d x and y coordinates of the GUI mesh like in this PG:
Then you can trigger a mouseEvent at those coordinates:
But also I am new to Babylon so maybe there is an easier way.
Iām not sure I understand this correctly. Could you explain āforce trigger click eventā? What is the context? Do you want to force the user to click on the GUI control - or - do you want to trigger the event from the GUI control whenever the user clicks anywhere or somewhere else in the scene? And then, why would you want to force trigger the event from the GUI anyway. You could just run it in a function and add the visual representation of the clicked GUI control. Adding to this, you could simply have (as I believe suggested above) just a variable of āisClickedā when running the function.
EDIT: Forgot to mention that āthereās what you CAN do and what you SHOULD doā. Again, I have no clue about the context or whether itās Option A (force click on control) or Option B (trigger event from control when clicking outside)ā¦but just BEWARE, If it is option B, thereās more than just the tech aspect (and also why this is, as you say āunconventionalā). Imagine the button would be like a consent āI AGREEā. It might be obvious to say in this case but Iām gonna say it anyway (just to make this clear). Implementing a behavior where clicking outside this button would still trigger the related event is illegal. And then, less obvious, even in the case of simple āgame actionā, it is still likely to decrease ātrustā and affect the CX.
Hey guys. Thank you for you answers. I redesigned my code to avoid this issue, so I will not be attempting the force click implementation
I tried to āhackā the process a bit, and kind of simulate what user would do in the app, so I can recreate the state of the app as I wish. A lot of stuff is happening on clicks on GUI elements, and many other events, so I thought I could force click my way to avoid state flow redesign.
Thanks guys, I will mark the issue as solved.