Search Unity

Bug Sticky Keyboard Input, keys get stuck in down state

Discussion in 'macOS' started by sameng, Nov 11, 2021.

  1. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    I just updated to the new Unity 2021.2.2.

    I have been having this Sticky Keyboard input problem for ages.
    This problem has actually been in several versions, I believe starting at around 2020.3.17.

    This problem seems to be getting worse in this new version. Maybe because editor performance has regressed.


    The problem is, when pressing down a key, sometimes Unity will not recognize that the key is lifted.

    It happens more frequently when frame rate is lower. I think it's related to the "lazy updating" the unity editor does. The stuck key gets resolved when any other key is pressed, or the mouse is moved.

    I submitted a report that uses Rewired so I can't post the project here.

    Case: 1380143
     
    midsummer likes this.
  2. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Oh. Just reproduced without Rewired.

    Just using "Input.GetKey( KeyCode.W) " will cause the bug... :(

    Probably this is specific to macOS editor. I really wish there were more engineers at Unity using macOS, cause the usability is getting worse every version. Not to mention the invisible, blacked-out-panels in the new version of Unity.

    But to be clear, I've been experiencing this bug since LTS 2020.3.17 on an intel mac (probably when the underlying Input changed.... and caused this bug). It's just even worse now in 2021.2.2.

    Repro steps:
    1. open SampleScene.unity
    2. tap W and S to move cube
    3. Sometimes, after tapping W or S, it will get stuck, making your cube continue moving forever.
    4. Move the mouse or hit any other key on the keyboard to "reset" the stuck input.
     

    Attached Files:

    unity_AkGames and Squize like this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yikes. Does this occur in built apps too? Or only in the editor?
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    This sounds like it's the exact same problem that affects the Windows editor. I've documented this issue here:
    https://guavaman.com/projects/rewir...#windows-editor-keyboard-keys-stuck-raw-input

    It was introduced in Unity 2019.3.8.
     
    JoeStrout likes this.
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    Actually, I re-read the OP and I think this is different than what I posted. I didn't realize the key was getting stuck forever. I thought he said it was getting stuck temporarily. That sounds like a different problem.

    Rewired uses UnityEngine.Input for keyboard and mouse input on MacOS, which is why Unity bugs in this area affect Rewired:
    https://guavaman.com/projects/rewired/docs/Overview.html#tested-platforms
     
  6. Dkalina

    Dkalina

    Joined:
    Jan 23, 2019
    Posts:
    3
    I'm experiencing a similar (or the same) problem on 2021.2.2f1 / 2021 14" Macbook Pro M1 Max running MacOS Monterey. Using the new Input System - version 1.1.1 - and I am not using Rewired.

    Have only tested in editor, but the best way to describe it is that the input actions for movement get stuck: I occasionally will take my hands off the keyboard and the input will continue to return a non-zero value until I touch the keyboard or trackpad. There's also often lag in the start of the same input action registering. I'm using the InputActionVisualizer to look at the action's output directly and it's easy to observe the lag / reproduce the stuck condition.

    There was a separate input lag issue in the context of the editor on 2021.2.0 but that has been fixed.

    Tried reproducing in a new project but with no success; perhaps due to very high frame rates.

    Would love to know if others are experiencing this in 2021.2.2f1 on Mac silicon with the new Unity Input. Thanks!
     
    JoeStrout likes this.
  7. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Still exists in new version 2021.2.3.

    It makes my game really unplayable. I don't know how to make a videogame with a faulty inconsistent inputsystem...

    Using WASD to move around... frequently Unity won't send a "key up" event and my character will continue moving in one direction forever.

    I attached the repro up above, which reproduces the issue without rewired, with just 1 script that uses Input.GetKey.
    It will reliably get stuck.

    Still no response from devs on this? Is this a known issue at least?
    Should I post on the Input forum as well? I already filed a bug (1380143)
     
  8. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    I can repro this. Thanks for your report. We will look into it. And thanks for the repro project. That helps a ton.

    It seems to only repro when frame time is very long (low FPS). Is this in line with your experience?
     
    Last edited: Nov 19, 2021
    sameng likes this.
  9. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    I'm pretty sure this issue was already present in the 2019.x versions, assuming similar issues with and without the new InputSystem are caused by the same things. Only the editor has ever been affected.
     
  10. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Thanks for taking a look at this!
    I think it's related to low FPS, but it still happens on my project even when it's running at 100+fps on M1 Max.

    On the 2019.X releases I was able to "bypass" the issue by setting the editor interaction mode to 33ms (30FPS).

    Sadly the same workaround isn't working on 2021.2.3, as I think that option is broken.

    I also tried setting Application.targetFrameRate = 30, which does indeed throttle the game to 30FPS, but it doesn't help workaround this issue in my case.
     
  11. Dkalina

    Dkalina

    Joined:
    Jan 23, 2019
    Posts:
    3
    In my case, I wouldn't say frame time is particularly high (it's a prototype, and I'm on an M1 Max, so generally things are 60hz+).

    But trying to reproduce in an empty project didn't work; frame time was miniscule and I didn't have the time to try and introduce artificial slowdown.
     
  12. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    This matches my experience. This bug causing sticky input makes for a miserable combo with the Apple Silicon editor bug where the FPS drops substantially in the GameView when the SceneView is open...
     
  13. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    I have exactly the issue you describe, with the same machine config, but I am not using the new input system at all.
     
  14. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    Regarding the Scene / Game view perf issue, that is unfortunately a known issue and is shared between the Intel and Apple silicon editors. Resolving that issue is non-trivial.

    But as far as this issue with sticky keys, I have feelers out to get to the root of the issue. The response will be delayed due to Thanksgiving and upcoming holidays in the US, but we are working to get to the bottom of it.
     
    unity_AkGames, sameng and aromana like this.
  15. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Thank you for the update, I really appreciate it. Currently my workaround is to use a gamepad, which works well enough for me to test my game in the editor.

    Just another note: I noticed that the sticky key issue also happens in the Editor sometimes, even not in play-mode. It leads me to believe that it's something that's not associated with the Input Systems, but actually just how the Editor is ticking.

    For example, sometimes using Arrow Keys to navigate the Scene View will also get stuck, even when outside of play mode. It seems to happen significantly more often in performance heavy scenes.
     
  16. Deleted User

    Deleted User

    Guest

    2021.2.4 kinda solved the lag issue but not the sticky keys sadly ... keep up the good work !
     
  17. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    I saw 2021.2.5 was released, anyone knows if the issue got resolved? Thanks in advance
     
  18. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    This isn't yet resolved. We are investigating what to do on our side as our investigation so far points to this at least partially being a macOS bug.
     
    sameng and aromana like this.
  19. Deleted User

    Deleted User

    Guest

    Also, the game view is never focusing on Mac, I have to click to focus. "Maybe" that's related ?
     
  20. Deleted User

    Deleted User

    Guest

    Any chance it's solved in 2021.2.6 ?
     
  21. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    71
    I've been having issues with editor input on macOS for at least a year now. I made a project to repo it on my end but the bug reporting team said they couldn't repo it on their end and they had no similar bug reports :/ (Case 1380856)
     
  22. jsm174

    jsm174

    Joined:
    Jul 22, 2015
    Posts:
    16
  23. Dkalina

    Dkalina

    Joined:
    Jan 23, 2019
    Posts:
    3
    I haven't even seen it acknowledged in the Release Notes yet. Would be nice to know that it's actually on the radar for being fixed - outside of this thread.

    I did adopt the "use a gamepad" workaround but that's not really a long-term solution.
     
  24. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    @Dkalina - yeah, I agree. The last contact I've had with anyone at Unity is someone from QA telling me they can't reproduce it... Which isn't exactly reassuring! I'd love an update on what's going on.
     
  25. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Would love to see this bug added as an official bug on the tracker, and added to the "known issues" list on releases.

    The bug I submitted on fogbugz is:
    Case: 1380143

    Current status: Open (no response from QA)
     
  26. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    The development team is definitely aware of this. Given our current investigation points to this being at least partly a macOS issue, we are determining how to mitigate how it affects users.
     
    petey, adslitw, jsm174 and 1 other person like this.
  27. Deleted User

    Deleted User

    Guest

    Hi @KevinWelton and Happy New Year !
    Is there any ETA for this ? Can we expect some solution this month ? Thanks
     
  28. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    I have started using a windows machine while all the Mac issues are sorted. I can't say for certain, but I'm fairly sure I have experienced this bug a couple of times today. Is this suspected to be a Mac OS only issue @KevinWelton, or would that make sense? I'm on 2021.2.7.
     
  29. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    This is a Mac-only issue.
     
  30. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    I've reached out to Apple for their help on the issue and perhaps how to mitigate the effects for users of older macOS releases. I can't give a timeline in good faith, however, since I don't know when they will prioritize this.

    The NSEvent isn't being delivered to Unity when expected. The timestamp on the NSEvent when it *does* finally get delivered is correct :eek:

    I'm continuing to sniff for workarounds that are realistic without their input, but no success yet.
     
    jsm174, Deleted User, jnho228 and 3 others like this.
  31. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    I am testing a fix for this issue. I'm pretty certain the issue was on our end after all. It was non-trivial to track down though.
     
    aromana, midsummer, adslitw and 6 others like this.
  32. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Wow! Thanks for keeping us updated. Fingers crossed that's it!
    If that turns out to be the cause, I'm super curious what it was and how you were able to track it down.
    Seems like it's an odd one...
     
  33. Deleted User

    Deleted User

    Guest

    Woohooo ! Hope it will make it to the next update :)
    Thank you again for your hard work.
     
  34. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
  35. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Great stuff! I'm also super interested to hear what the issue turned out to be. I love a good bug hunt / fix story!
     
    aromana likes this.
  36. jnho228

    jnho228

    Joined:
    Sep 6, 2018
    Posts:
    15
    I know a fix is potentially incoming (hopefully) relatively soon, but is there anyone else doing active development on an M1 device using any version of Unity currently? Fully up to date versions of the 2020 LTS, 2021, and 2022 beta all have the keys periodically stuck on down issue for me. I had no issues on the 2020 LTS version before updating to Monterey, so I'm wondering is this really 100% Unity or is it somewhat a macOS issue as well.
     
  37. jsm174

    jsm174

    Joined:
    Jul 22, 2015
    Posts:
    16
    @jhno228 - I am doing active dev on an M1 and have had this issue for a while now (on my intel too).

    We are working on a pinball project and have the flippers controlled by the keyboard. Obviously not good since they get stuck up.

    Anyway, was hoping to see some reference to 1380143 in yesterday's release notes (https://unity3d.com/unity/beta/2022.1.0b3) but still nothing..
     
  38. Deleted User

    Deleted User

    Guest

    FYI 2021.2.8f1 same issue ... let's wait for 2032.2.f1 :))
     
    adslitw likes this.
  39. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    I've been trying to use an M1 Pro as my primary dev machine, but (at least in my case) it's just not feasible yet. In between the input issues, the editor spikes, physics processing spikes and multiple Metal issues, it's unusable for me. I've actually, for the first time in 10 years (since I started using Unity 3!), switched over to Windows while I wait for this all to blow over.
     
  40. Deleted User

    Deleted User

    Guest

    I'm on M1Max; except the input (which you can bypass with gamepad) all is workable for me (I'm back on builtin); I don't notice any editor spikes; but it might be just me. But yes I agree, it sucks - especially having done all the 'marketing' Apple-side 'yeah it's amazing it works great !' ... reality is ... meh ... just wait and see, we'll get there eventually !
     
    adslitw likes this.
  41. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Yeah it's tough to know exactly what is project specific vs. a more general editor / OS issue. However I will say I'm not doing anything that should be pushing the CPU or GPU. From a totally subjective perspective, on Windows in playmode my game feels fluid and responsive. On Mac OS it's dropping frames, missing input, laggy and feels like... mush. The best way of describing it is that it feels like I'm playing through treacle!
     
  42. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Using the same exact hardware, same project, resolution etc etc, when I dual boot my Intel MacBook (i9, 5500M) into Windows, it runs the Unity Editor so so so much smoother.

    And when running a build of the project under macOS, it actually runs super smoothly too. It's the macOS Editor for me that has the biggest bugs.
     
    adslitw likes this.
  43. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Yep, agreed. Glad it's not just me!
     
  44. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Just throwing my hand up here. I’m on a MacBook Pro 16 (intel) and it still happens (but it sounds like way less).
    Sounds like M1 is unusable and intel is just super annoying and disruptive.
    I’m really hoping to get back to some normalcy soon! Please, keep us in the loop :)
     
  45. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    I’m using 2021 Silicon edition on my M1 Pro. It’s generally stable and performant, but surely not as much as it would be under windows with equivalent hardware.
    I think the simple fact is that the
    majority of Unity’s big customers increasingly use Windows, not Macs. So, making the editor great on Macs is lower priority than Windows, which has been a clear trend to me as a user of both systems for the past several years. And I can’t say I blame them, but it’s disappointing as a Mac user and given Unity’s history starting out on the Mac.
     
    Deleted User likes this.
  46. Deleted User

    Deleted User

    Guest

    Agreed, we just need to be patient - we'll get there eventually
     
  47. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
    Sorry, I understand this is a thread for the MacOS issue, but is there a discussion around the stuck keys in Windows editor 2020.3.21? We've been having this issue on all projects where `Input.GeyKey` will return true after key release (thankfully not in build). Because this is the top google result it would be nice to link here if anyone is aware of an existing discussion.
     
  48. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    @rhys_vdw - not that I'm aware of. I felt like I maybe noticed it a couple of times, but @KevinWelton confirmed it's a Mac only bug, and I've been working on PC for a few weeks now and can't say I've had any issues (This is using 2021.2 however, I haven't been using 2020.3).

    How often is it happening? New input system, old input system etc?
     
  49. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
    @adslitw Old input system. Infrequently, but enough to be noticed by one user on mac and myself on windows. I spent a long time debugging it before concluding that it's a Unity bug. It's a tough one because it clears as soon as you focus any editor window.
     
  50. KevinWelton

    KevinWelton

    Joined:
    Jul 26, 2018
    Posts:
    239
    A candidate fix for this will be in 2022.1.0b6. I want to give it more time to bake before I put it in 2021.2 though. I have top people helping me take a look at this fix holistically. I don't want to jump the gun.

    So When 2022.1.0b6 is released, I'd be interested in your feedback.