Search Unity

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:
    111
    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.