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

Package: UI Toolkit

-

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.

  1. 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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.