WebGL be able to configure click event listener

Hey,

We’re trying to migrate from the old UnityEngine.Input system to the new input system and we’re having some issues with click detection on WebGL. Our web application runs Unity WebGL in an HTML canvas with additional HTML elements on top of the Unity canvas.

In the old input system, we used Input.GetMouseDown(0) to check if the user is left clicking. The great thing about this approach is that it automatically accounts for the other HTML elements (the ones on top of the Unity canvas). If the user clicks on an HTML element that is not the canvas, Unity would not detect this as a left click. Input.GetMouseDown(0) would only return true if the user clicked on the canvas itself; not on any other element.

For the new input system, we set up an action that is listening to Left Button [Mouse] with a Button action type. Then, in the code we check if the user is left clicking using _input.Player.LeftClick.performed += … and performing logic whenever that event fires. The problem is that this event fires regardless if the user clicks on the Unity canvas or not. If the user is clicking on an HTML element that is on top of the Unity canvas, the input system will still detect it as a click. This does not match the behaviour of the old input system.

We looked further into the generated WASM to try and figure out what exactly is going on. It looks like the registration function used by Unity for mouse click input is emscripten_set_mousedown_callback_on_thread. It seems like it’s using a target parameter of 2, which looks like it stands for document (screenshot attached).

If instead we substitute that above for $WebGL_UnityCanvasSelector__, this fixes our issue. In other words, it seems feasible to add some configuration to let us choose whether or not we want to register clicks on a document level or on a canvas level.

Would it be possible to add this configuration to the input system? The hack above isn’t feasible for production and there’s no good workarounds.

Thanks!

1 Like

Hey,

This sounds more like a bug in the WebGL platform layer.
Will you please file a bug report for this issue?

As an aside, platform specific aspects of a feature are handled by a completely different team, i.e. the Input team doesn’t really work on or know much about WebGL and likewise the WebGL team probably isn’t watching the Input forums too closely. Filing a bug report will ensure the information gets to the proper team.

Bug report here: Jira Service Management

Did this issue get resolved?

I checked the ticket status and saw a request was made by QA for a repro/test project, but the person who filed the bug never responded. So the ticket was closed.

If you’re encountering a similar issue, please file another ticket (can reference the original) and provide a repro project.

Also, since this is WebGL specific, I suggest posting about this on the WebGL platform forum.

Made a new thread in the WebGL forum here New Input system listens for click event on whole document instead of canvas

The person who filed the ticket was one of our interns. They wrapped up their term and no longer have access to their email; that’s why no one responded to QA. Sorry about that!

Thank you!