Search Unity

Input.GetAxis gives me weird values after a while

Discussion in 'Scripting' started by dennik, Nov 14, 2020.

  1. dennik

    dennik

    Joined:
    Nov 23, 2011
    Posts:
    101
    I've built a simple controller that reads values from Input.GetAxis("Horizontal") and Input.GetAxis("Vertical").
    For some reason, after the game runs idle for a few minutes, especially if the game window loses focus (on windows10), I'm starting to get values -1 and 1 for the horizontal and vertical axis. Not only that, but it reads the mouse button as input! Any explanations?
     
    Last edited: Nov 14, 2020
  2. dennik

    dennik

    Joined:
    Nov 23, 2011
    Posts:
    101
    BTW I wanted to mention that, while this happens, If I click to select something on the scene view and then click back to the game view, everything goes back to normal.
     
  3. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    I can confirm. In Game view, all is OK. I click back and forth from Scene to Game, all good. I bring up Chrome (or any other app I believe), then go back, and it's at -1 and 1. Then if I click Scene, it's right, but Game will go back to -1 and 1. Weirder still, if I open the Console, it will fix the issue. Didn't have to wait at all, it happens right away when you open another app.

    More distressing, when it's in -1 and 1 mode, the keystrokes for the axes don't work...

    I'd submit a bug report.
     
    dennik likes this.
  4. dennik

    dennik

    Joined:
    Nov 23, 2011
    Posts:
    101
    Thanks for confirming and submitting this bug. I spend many hours trying to debug this to no avail.
     
    seejayjames likes this.
  5. dennik

    dennik

    Joined:
    Nov 23, 2011
    Posts:
    101
    Please let me know when you do, is that on github? I'd like to follow the discussion.
    Thanks.
     
    seejayjames likes this.
  6. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    691
    No, I submitted the report (no project as it's so simple). They weren't able to reproduce the error, so I don't know what's up....weird!
    It's really not a deal-breaker as it's a bit of an edge case, but it's definitely strange.
     
    curiosissimo likes this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    One workaround you probably should be doing anyway is to implement OnApplicationFocus() somewhere and pause the game when focus is lost. It's often best to guard that so it doesn't happen in Editor because then scene debugging becomes extremely annoying if every time you inspect the hierarchy your game pauses.
     
  8. curiosissimo

    curiosissimo

    Joined:
    Sep 28, 2017
    Posts:
    3
    It's happening the same to me!
     
    dennik likes this.