Focus() on TextField throws an Exception (UI Toolkit bug)
When creating a new situation, we give focus (Focus()
method) to the text field inside the situation to select the default situation name so that we can directly type a new name on the keyboard. However this causes an exception, which makes the text invisible. Writing something appends to the default name ("New Situation"). In this case, we currently need to rename the situation using the contextual menu (for some reason, the Focus()
method works here...).
This bug is related to UI Toolkit. See https://forum.unity.com/threads/indexoutofrange-exception-when-setting-focus-on-a-text-field.1185379/
Hopefully, a future update of UI Toolkit will resolve the bug. Suggested workarounds did not work in this use case.
Edited by Chris Warin