Search Unity

Web GL Mouse Input Glitch on Chrome

Discussion in 'Web' started by ATMEthan, Apr 27, 2017.

  1. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Hey Unity Community,

    I've come across a problem in my Web GL export. My application is a pretty simple 3D model viewer. You can click the background to move the model, you can right click to rotate the model, you can pull the the pieces of the model apart to see the inner workings and a bunch of other things. My problem lies within functionality where you click the background to move the model. But I'm fairly certain this is a specific Chrome issue. I cannot replicate this on Firefox. Here are my replication steps:

    1 - Click 3(or more) times on the background using mouse button(0)
    2 - Hold the mouse button(0) down and drag
    3 - Let go of the mouse button
    4 - Now the application will be stuck always returning true for Input.GetMouseButtonDown(0) and Input.GetKey(KeyCode.Mouse0)

    I can confirm this b/c the Chrome console continuously prints my debug log that is wrapped in an if(Input.GetKey(KeyCode.Mouse0)) - Video demonstrating the issue -
    .

    I test my Web GL export locally by two different means. Running Chrome with the flag "--allow-file-access-from-files" and by using the Web Server for Chrome extension. I highly doubt this is causing the issue but as I learned never rule out a possibilities until you know explicitly what it is.

    Also, another weird thing I've noticed is right before the application gets stuck the mouse cursor changes from the standard cursor icon to the circle with a strike through it. Once I see that appear I let go of the mouse button and it gets stuck. I felt that was worth mentioning.

    Unity 5.6.0f3
    Chrome 57.0.2987.133
    Chrome 58.0.3029.81

    I'm wondering if anyone has encounter this issue and found a solution or work around. Or if anyone has some ideas on how I might be able to go about fixing this on the Unity side.

    Thanks for any and all help
    -Ethan!
     
    Last edited: Apr 27, 2017
  2. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    595
    Google Chrome start to be boring now ... They have dropped the support of unity web player 1/2 years before firefox and they are not able to release something working good in WebGL. Firefox just dropped it a month ago and his WebGL is good !

    I have reported 2 bug for google chrome a month ago and it's still not fixed !

    Bug 1 (Pointer Lock movementX/Y values jump when scroll wheel used) : https://bugs.chromium.org/p/chromium/issues/detail?id=701970

    Bug 2 (The mouse scroll foward or backward give a negative value when the cursor is locked) : https://bugs.chromium.org/p/chromium/issues/detail?id=701965

    The bug number 2 has been fixed in canary but not merged in the last Chrome update ..... and they tell me :
    "I've fixed this in M59, but didn't request a merge to M58 as this isn't marked as release blocker, and I didn't consider it important enough to merge."

    WTF ! Not important? They just have broken a lot of game. These people are too lazy or too slow? Or maybe it's because i'm french and want everything perfect as it should be?

    Anyway, if your bug is an issue from chrome, you must open an issue here https://bugs.chromium.org/p/chromium/issues/list

    Have a good day.
     
    Newtori likes this.
  3. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Thanks for the information Roka but I don't think your information really helps me.

    Also, I think I wasn't clear enough in my original post. I'm wondering if anyone has encounter this issue and found a solution or work around. Or if anyone has some ideas on how I might be able to go about fixing this on the Unity side. I'll put this in my original post as an edit as well.
     
  4. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
  5. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    I see something like that, i have a player controlled by the arrow keys on the keyboard.

    when i press the arrow to make the player run, the key gets stuck in the down position so even when you release the key the player keeps running for ever, and you cant stop it. sometimes if you keep hitting the key it will release and it will stop.

    When i say "stuck" mean stuck in the software (the mechanical key itself is not stuck). The software keeps reporting the key as pressed even when it was released. Same deal for the mouse sometimes.

    Also other problem is that sometimes in WebGL the player can easily run though walls (colliders) and even the terrain itself, for example if i have a terrain where part of it is a mountain, if the player is running he can easily ignore the slope of the mountain and run right though the ground and end up inside the mountain terrain. I dont know how to stop that from happening, seems to be game engine issue?
     
    Last edited: May 2, 2017
  6. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Hey,

    I ended up submitting a bug report and Unity is looking into it. You can track my issue here: https://issuetracker.unity3d.com/is...ate-of-getmousebutton-0-always-returning-true

    nsmith1024 I suggest making a blank project and seeing if you can reproduce the bug in the blank project. If so submit a bug report to Unity. That's what I did. My issue only happens on Chrome and recently Unity testers found out on Microsoft Edge too so it definitely does seem like something is happening within the game engine that is causing this. Or it could be a coincidence and there's a problem both in Chrome and Edge

    Best of luck,
    -Ethan
     
    guneyozsan likes this.
  7. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    thanks Ethan
     
  8. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    242
    I am experiencing this issue as well.

    Edge has/had this issue as well, but this was actually and Edge issue - supposedly fixed in the Creators update (https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9021586/ ). However, reports are that it is still not fixed.

    For Chrome this is more serious - IMO - as I am quite sure this issue is caused by Unity and not Chrome.
    I have builds of our game made in 5.5.0f3 and 5.6.1f1. The mouse/key lock issue occurs only on the newer build, the older build has never shown this issue. Maybe it is related to the issue that mouse cursor visibility is not working in newer builds etiher. Feels like a longshot, by you never know...

    I am at a loss at the moment on how to fix this. I find it hard to reliably reproduce as well.
     
  9. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    242
    I looked into this issue a while longer - using the sample project by @ATMEthan

    Tried the Input Manager (Fire1) instead of directly using Input.GetMouseButton... and testing if anything of the Input settings (sensitivity, snap, etc.) would help. To no avail...

    However, when testing I noticed the actual cursor behavior in the browser. It felt like I was actually trying to drag the webgl content - like you can drag an image directly from a webpage.

    I changed the .css file to not allow the webgl content to be selected anymore. E.g.
    Code (JavaScript):
    1. .webgl-content * {border: 0; margin: 0; padding: 0; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; }
    Sorry for the Javascript encoding, but this should be more clear than a simple copy/paste.

    I haven't experienced the issue yet(!).

    So not actually a solution or a better understanding of the issue, but at least there seems to be a workaround.

    In retrospect this might not be an Unity issue after all. Maybe Chrome just handles things differently than Firefox with the new 5.6 webgl embedding api. I don't know...

    Hope this is helpful!

    -Pieter
     
  10. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    I give this a try Pieter! Thanks for the info.
     
  11. KevinGelking

    KevinGelking

    Joined:
    Jul 17, 2014
    Posts:
    15
    Thanks for the pointers @ Unity Issue Tracker and the .css. :)
     
  12. blusailsgaming

    blusailsgaming

    Joined:
    Feb 15, 2018
    Posts:
    1
    Pieter, this solution is huge. Solved my super unpredictable mouse input issues on chrome. Thanks! Unity needs to include this in their build settings.
     
    PieterAlbers likes this.
  13. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
  14. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    595
  15. jimrif

    jimrif

    Joined:
    Jul 3, 2012
    Posts:
    6
    I know this is a old post but this issue with the Input.GetKey function on Chrome still exists, although not really the bug in this topic. I wanted to mention a workaround I found after a few hours for people who might find this thread looking for the issue like I did.

    run the webgl in an iframe and the keyboard input issue is no longer present in Chrome.
     
  16. brownce

    brownce

    Joined:
    Sep 14, 2015
    Posts:
    18
    Thanks for this. It seemed to help. I could still trigger the issue if I clicked and dragged off the game canvas part, but that is a small detail and it's better than it just seeming to randomly happen when dragging on the canvas itself.
     
  17. keshav9999

    keshav9999

    Joined:
    Feb 8, 2019
    Posts:
    3
    Where can i find the .css file mentioned above?
     
  18. brownce

    brownce

    Joined:
    Sep 14, 2015
    Posts:
    18
    When you do a webGL build, there should be an included .css file.