Search Unity

Bug How can I enable active polling to workaround this gamepad drift bug?

Discussion in 'Input System' started by alfish, Sep 28, 2020.

  1. alfish

    alfish

    Joined:
    Apr 5, 2017
    Posts:
    26
    The new Input System documentation says:
    How do I enable polling for gamepads on all platforms? I'm having bugs in Linux (Kubuntu) with a wireless Bluetooth controller (8bitdo, I think it should be XInput, but it's recognized as a generic Gamepad, not as Xbox Controller).

    The problem happens when I push the analog stick forward and back to zero. Sometimes it drifts - that is, although the stick value should be back to (0.0, 0.0), it doesn't update, so the character keeps walking on its own on the last received value forever. This bug is quite annoying to test, since it happens randomly. Here's a piece of the code I used to detect it:
    Code (CSharp):
    1. public class Player : MonoBehaviour {
    2.   public InputActionReference moveAction;
    3.   //...
    4.   Vector2 hangInput;
    5.   float hangSince;
    6.   void Update() {
    7.     var movement = moveAction.action.ReadValue<Vector2>();
    8.     if (movement == Vector2.zero || movement != hangInput) {
    9.       hangInput = movement;
    10.       hangSince = Time.time;
    11.     } else if (Time.time - hangSince > 1) {
    12.       // gets here when drift is happening; try many calls to test if something
    13.       // can trigger a refresh of input without user interaction; nothing works
    14.       // except that old Input.GetAxis("Horizontal|Vertical") gets right value
    15.       // but it doesn't trigger a refresh on new Input System
    16.     }
    17.   //...
    18.   }
    19. }
    The thing is, I'm sure it's a problem with the Input System, since Input.GetAxis returns the correct value. Also it refreshes it to the correct value when I press any button, key or move the mouse (even if I don't touch the controller). So this has to be a bug in Input System itself, not on the driver for Linux.

    I tried many things to work around it (from calling many properties on Gamepad, to writing stuff on event queue; even InputSystem.Update) to see if it would somehow refresh the Input values via code (so I could do it periodically) but nothing works.

    Can I enable some setting or do some workaround to enable active polling for all gamepads on any platform, instead of this passive mode?
    Since this bug might happen, I think developers should have the option to choose to be safe instead of efficient. Controller drift is just unacceptable to players, so this would force me to use the old system and I really don't want to because the new system's structure is FAR superior.
     
  2. alfish

    alfish

    Joined:
    Apr 5, 2017
    Posts:
    26
    Also, unrelated bug:
    The keyboard mapping is all wrong in the Editor (runtime works). This is only wrong on the new Input System (the same happens in both mappings "By Location of Key" and "By Character Mapped to Key").
    Unity 2020.1.4f1, Kubuntu 20.04, KDE Plasma