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
- Skinned Mesh Renderer with multiple Animator Components does not render when "Optimize Game Objects" is enabled
- [iOS]Certain characters are not displayed when using iOS devices with 18 OS and newer
- Trees do not render in 'Unity Terrain - URP Demo Scene'
- Silent crash when clicking in Scene View in a specific project
- The Player renders black on a Quest headset when MSAA, Post Processing, and Spacewarm depth submission are 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.