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
- Shader transparency, discard, and clip are not working when using the Player
- Error is thrown when clicking on warning in the console
- Long IL2CPP build time when project has a .ufbx library wrapper
- Cursor doesn't change to the resizing when using the Rect Tool and the Sprite is too close to the bottom of the Scene View
- InvalidOperationException exception is thrown when Editor Default Text Rendering Mode is set to "Bitmap" and Editor Font is set to "System Font" and an array is expanded in the Inspector Window
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.