4.3 Bug; Focused Text Field may not be editable

I have the following code;

     private void OnGui()
     {
            GUI.SetNextControlName("SearchField");
            Search = EditorGUILayout.TextField(Search, GUI.skin.FindStyle("ToolbarSeachTextField"));

            [...]

            if (GUI.GetNameOfFocusedControl() == string.Empty)
                GUI.FocusControl("SearchField");
     }

If the method “GetNameOfFocusedControl” is to be believed, the control named “SearchField” is properly focused.
However, the text field is not editable. If I manually click on the text field, it becomes editable.

This code works fine on 4.2 and earlier versions.

I concur, very similar code stopped working for me with 4.3.0.f4

I tried

  1. Setting the focus every frame
  2. Setting Focus to “” then to my field
  3. Changing my field name (coincidentally, it was “SearchField” for me too).

None if it helped. FocusControl seems broken.

Edit: This seems to be on and off, sometimes it works. I’ll update if I nail the repro conditions.

Here is a workaround. It seems there is a different method to focus TextFields. Go figure…

GUI.SetNextControlName("SearchField");
string newSearchString = EditorGUILayout.TextField("Search:", _searchString);
GUI.FocusControl("SearchField"); // Kept this one, just in case.
EditorGUI.FocusTextInControl("SearchField"); // Calling a different method for TextField.

See: FocusTextInControl

I’m not sure if it’s a bug; when using FocusControl (rather than FocusTextInControl), you can use the return key to toggle the focused textfield being editable or not.

–Eric

Well, I guess it’s a new method. Kinda annoying to see existing method’s behaviour changes without any kind of documentation about it. :stuck_out_tongue:
BTW, relying on user input to palliate to a broken behaviour is not acceptable in how I code my tools.