Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Input.GetAxis returning value after a controller is disconnected

Discussion in 'Scripting' started by Poupi, Jan 18, 2017.

  1. Poupi

    Poupi

    Joined:
    Jan 11, 2012
    Posts:
    108
    Hello everyone !

    I'm having an especially annoying issue with Unity's Input Management. When a controller is disconnected while giving an input on an axis (let's say the vertical axis), the value on this axis isn't set to 0. I have to reconnect the controller again and move a joystick to reset the value of the vertical axis to 0.
    This is super annoying if people are playing with a wireless controller running out of battery, the character will still move.
    Is there any way to avoid this behavior ? I know we can't manually set a value for an axis, and it's a bit late for us to abstract this GetAxis thing so we can handle this stupid behavior.

    Many thanks !
     
  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    You can query the Input.GetJoystickNames() and see if the controller is still connected. If its not don't get values from Input.GetAxis(string) since there is no joystick to query. Thats about as good as it gets.
     
unityunity