Search Issue Tracker
By Design
Votes
1
Found in [Package]
Built-in
Issue ID
1409262
Regression
No
[UIToolkit] Keyboard events are not properly registered when the Escape key is pressed first on awake
Reproduction steps:
1. Open the attached project "UITK Android BackButton.zip"
2. Press the escape key on the keyboard and observe that nothing happens (even multiple times pressing escape)
3. Press any letter from the keyboard and observe that the event is received and the label shows the letter's keycode
4. Press the escape key on the keyboard again and observe that now the Escape keycode is shown.
Expected result: Event is received when the Escape key is pressed first
Actual result: Event is not received when the Escape key is pressed first
Reproducible with: 2019.4.36f1 2020.3.31f1, 2021.2.15f1, 2022.1.0b12, 2022.2.0a8
Notes:
-Sometimes even the other keys are not properly registered, only after clicking multiple keys at the same time awakens the event. The UIToolkit EventDebugger shows the event but the `VisualElement` does not receive the event.
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
- GetCurrentAnimatorClipInfoCount() and GetNextAnimatorClipInfoCount() return 0 when animator is in transition
- 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
Resolution Note:
Key events are dispatched through the hierarchy to the element that has focus. Is no element has focus, then the Key events are sent to the PanelSetting's root element (the parent of the UIDocument's rootVisualElement).
Calling _backButton.Focus(); during the NavigateUI initialization will lead to the desired behaviour
User project also did initialization during Awake and Start which can lead to null references after a domain reload. Moving the initialization code into OnEnable is the recommended way to assign references to VisualElement and register callbacks as new instances are recreated during the domain reload.