Search Unity

Bug Disabling OnScreenControl in Update breaks first click of UI Button

Discussion in 'Input System' started by angusbjones, Sep 14, 2021.

  1. angusbjones

    angusbjones

    Joined:
    Nov 24, 2012
    Posts:
    8
    When an OnscreenControl (Joystick or Button) is enabled/disabled outside a UI event (such as during Update()) the next click of any UI button doesn't perform the click. This issue doesn't occur when the OnscreenControl is enabled/disabled through the event system immediately.
    I've submitted a bug report for this issue already which contains a basic scene to replicate it: https://fogbugz.unity3d.com/default.asp?1365070_blafnnpo280fj2o2

    For our project, this bug is encountered when moving from a game scene that uses an OnscreenJoystick to a menu-scene/overlaid-pause-screen. Once in the menu-scene/pause-screen, the OnscreenJoystick has been disabled and the first click of any button only causes a focus capture on the button (even appearing as Selected in the EventSystem), the actual click event is only triggered from the second click onwards.
    All scene loads and in-scene transitions are performed using promises so being able to perform enables/disables outside the default UI event system is critical.

    I wanted to add further detail and a workaround for anyone encountering the bug while waiting for it to be resolved who also don't have the simpler option of just performing the enable/disable within a UI EventSystem event:
    The issue appears to stem from the removal/addition of the OnscreenDevice from the InputSystem when the final/first OnscreenControl is removed/added during play.
    The bug can be worked around by adding an OnscreenControl (I've used a button) of zero size, with no visual component, bound to an unused ControlPath of the same device type as the OnscreenControl you're enabling/disabling (for instance, my real control I've bound to Gamepad->LeftStick and so my workaround control is also bound to a Gamepad control, Gamepad->LeftTrigger). This hidden, unused OnscreenControl needs to stay enabled across scenes so that the OnscreenDevice is never removed from the device list.