Search Issue Tracker
By Design
Votes
0
Found in [Package]
2019.4
2019.4.8f1
2020.2
2021.1
2021.2
Issue ID
1311114
Regression
No
Virtual Mouse Cursor calls OnClick event twice when doing a submit action with a gamepad
How to reproduce:
1. Open the attached project's "case_1311114-Project.zip" Scene labeled "GamepadMouseCursorSample"
2. Enter the Play Mode
3. Navigate the Virtual Cursor over the "Button 1" using the gamepad's Left/Right Stick
4. Click the UI Button using the gamepad's South button
5. Inspect the Console Window
Expected result: After pressing and releasing a button, the OnClick event is called once
Actual result: OnClick event is called on a button-down and button-up events
Reproducible with: 1.0.2, 1.1.0-preview.3 (2019.4.20f1, 2020.2.4f1, 2021.1.0b6, 2021.2.0a4)
Couldn't test with: 0.2.1-preview (2018.4.31f1, the Virtual Mouse sample is not available)
Notes:
- With Input System 1.1.0-preview.2, 1.1.0-preview.3, the OnClick event is triggered twice after the click instead on button-down and button-up
- The first click works as expected by triggering the OnClick event once but clicking on another button triggers the first clicked button event on the button-down
-
noio
Feb 22, 2021 08:29
I managed to work around the issue by checking if a "ISubmitHandler" is currently the "Selected GameObject", and then ignoring the button press (not copying state the state from the Click action into the virtual mouse)
void OnButtonActionTriggered(InputAction.CallbackContext ctx)
{
var isPressed = ctx.control.IsPressed();GameObject selected;
if (isPressed
&& (selected = EventSystem.current.currentSelectedGameObject) != null
&& selected.activeInHierarchy
&& selected.TryGetComponent(out ISubmitHandler submitHandler))
{
/*
* Return if a "Submittable" gameobject is currently selected,
* because that means the gamepad button is going to perform
* the submit action, and we do not ALSO want to process a click
* action at the location of the cursor
*/
return;
}var button = MouseButton.Left;
_virtualMouse.CopyState<MouseState>(out var mouseState);
mouseState.WithButton(button, isPressed);
InputState.Change(_virtualMouse, mouseState);
}
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- GPU utilization increases by 20% on Meta Quest headsets when Render Graph is enabled on 6000.0.16f1 and higher
- Value on Slider (Int) control in UI Builder displays as default when saving UI Document
- Color mismatch in UI Builders Library panel when the Editors theme is set to Light Mode
- [Android ] "AndroidJNI.ToBooleanArray" returns a random non-zero value instead of "IntPtr.Zero" when the method argument is null
- Non-HDR color picker opens when selecting material color with HDR enabled
Resolution Note:
Double-clicking comes from also having the "Submit" action hooked up. When using the gamepad to drive pointer input in the UI, it is important to not also have it hooked up to the navigation-type input actions.
Adding text to the docs for this.
Also, when we have "routing" of input on actions, we will likely be able to solve this internally and resolve the conflict even if both navigation and pointer-type input are set up for the same device.