Search Unity

Any way to work around UI/gamepad bug?

Discussion in 'Windows' started by pumpkinszwan, Mar 23, 2017.

  1. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Due to this bug in Unity: https://issuetracker.unity3d.com/is...before-releasing-xbox-one-controller-button-a

    I can't release my game on my main target platform (UWP). It doesn't look like the bug is going to be fixed.

    Does anyone know of a way I can work around this? The issue is that gamepad input on the UI repeats (e.g. a single button tap will be interpreted as multiple taps, which causes the player to inadvertently press buttons in the UI). It is extremely frustrating. The issue only occurs with gamepads in UWP builds as far as I can tell.

    Is there a way to ignore button presses in the UI (so I can manually handle them elsewhere)?
     
  2. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I have created a workaround for this in case others want to use gamepads with Unity UI in UWP.

    The problem is that a UI input press (e.g. from a gamepad's 'A' button) behaves as if the UI is checking if the button is down rather than if the button was pressed on that frame, i.e. a single tap is interpreted as multiple taps, which will trigger a button presses on the next screen, etc.

    In my game, pressing the Start button would load the next screen, then immediately action the first button on the next screen, which would navigate back to the main screen, then trigger the Start button again in a loop. A regular button tap would typically action at least 2 button presses, meaning navigating the menus was completely broken on UWP.

    To resolve it, I created a check in my input manager script that returns true if it has been 0.2 seconds since the last input. So whenever a button is pressed, the script that handles the button click checks if it is allowed to process it (i.e. if 0.2 seconds has passed since the last button was handled).

    This is working so far in testing on PC. Have yet to test the Xbox One, but it should be the same.