Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feature Request WebGL be able to configure click event listener

Discussion in 'Input System' started by wvandierdonck, Nov 21, 2022.

  1. wvandierdonck

    wvandierdonck

    Joined:
    Sep 13, 2022
    Posts:
    3
    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!
     

    Attached Files:

    louis_unity511 likes this.
  2. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    408
    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.
     
  3. wvandierdonck

    wvandierdonck

    Joined:
    Sep 13, 2022
    Posts:
    3
  4. schwab16

    schwab16

    Joined:
    Feb 22, 2023
    Posts:
    8
    Did this issue get resolved?
     
  5. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    408
    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.
     
  6. louis_unity511

    louis_unity511

    Joined:
    Feb 3, 2022
    Posts:
    2
  7. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    408
    Thank you!