Search Issue Tracker
By Design
Votes
0
Found in
2018.3.0a1
2019.1.0a1
2019.1.0f2
2019.2.0a1
2019.3.0a1
Issue ID
1149053
Regression
No
MoveMouseEvent.button returns 0 both when no button is pressed and when the left mouse button is pressed
How to reproduce:
1. Open the attached "case_1149053-MouseMoveButton.zip" project
2. Open the "BugReport > ExampleWindow" window
3. Move the mouse around in the "Actual Behavior" box, notice that MoveMouseEvent.button returns 0
4. Move the mouse while holding the left mouse button around in the "Actual Behavior" box
5. Inspect the MoveMouseEvent.button return value
Expected results: MoveMouseEvent.button returns different values when moving the mouse with or without clicking the left mouse button
Actual results: MoveMouseEvent.button returns 0 both when moving with and without clicking the left mouse button
Reproducible with: 2018.3.14f1, 2019.1.1f1, 2019.2.0a14, 2019.3.0a1
Note: Could not test in 2017.4 due to missing namespace errors.
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
- Placeholder asset is not loaded with Advertisement Legacy sample when using the latest version of the package
- Addressables content build fails but the Player build is successful when building a development build
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
Resolution Note (2019.3.X):
Hello,
As of today this an expected behaviour and the issue is a shortcoming of our current API.
This comes from the fact that the "button" property reflects the native event "button" property for which "0" means left.
https://docs.unity3d.com/ScriptReference/Event-button.html
However UIElements translates both MouseDrag and MouseMove native event types to the same MouseMoveEvent object.
The "button" property is only meaningful for Drag events, so the suggested workaround to read the underlying native event type to detect a proper drag:
For example testing with "evt.imguiEvent.type == EventType.MouseDrag" will work.
https://docs.unity3d.com/ScriptReference/UIElements.EventBase-imguiEvent.html
In 2019.3 we will introduce a more usable API which will expose a bit mask to test for pressed buttons.
Thanks for reporting this issue, hopefully this will do for now.