Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

4.3 Bug; Focused Text Field may not be editable

Discussion in 'Editor & General Support' started by LightStriker, Nov 13, 2013.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I have the following code;

    Code (csharp):
    1.  
    2.      private void OnGui()
    3.      {
    4.             GUI.SetNextControlName("SearchField");
    5.             Search = EditorGUILayout.TextField(Search, GUI.skin.FindStyle("ToolbarSeachTextField"));
    6.  
    7.             [...]
    8.  
    9.             if (GUI.GetNameOfFocusedControl() == string.Empty)
    10.                 GUI.FocusControl("SearchField");
    11.      }
    12.  
    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.
     
  2. OLP

    OLP

    Joined:
    Oct 19, 2012
    Posts:
    6
    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.
     
    Last edited: Nov 14, 2013
  3. OLP

    OLP

    Joined:
    Oct 19, 2012
    Posts:
    6
    Here is a workaround. It seems there is a different method to focus TextFields. Go figure...

    Code (csharp):
    1.  
    2. GUI.SetNextControlName("SearchField");
    3. string newSearchString = EditorGUILayout.TextField("Search:", _searchString);
    4. GUI.FocusControl("SearchField"); // Kept this one, just in case.
    5. EditorGUI.FocusTextInControl("SearchField"); // Calling a different method for TextField.
    6.  
    See: FocusTextInControl
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    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
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Well, I guess it's a new method. Kinda annoying to see existing method's behaviour changes without any kind of documentation about it. :p
    BTW, relying on user input to palliate to a broken behaviour is not acceptable in how I code my tools.