Search Unity

GUI.GetNameOfFocusedControl & GUI.SetNextControlName issues Unity 2017.2

Discussion in 'Immediate Mode GUI (IMGUI)' started by SpookyCat, Oct 24, 2017.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,768
    Hi All
    Is anyone else having problems with GUI.GetNameOfFocusedControl & GUI.SetNextControlName in Unity 2017.2? Editor scripts that have worked in all versions of Unity up to 2017.2 and also work in 2017.3 don't work in 2017.2 because GetNameOfFocusedControl is always returning an empty string. Is there a know issue or any workaround, the fact the scripts work in 2017.1 and 2017.3 but not 2017.2 makes me think there is something going on in Unity.
    Chris
     
  2. Andrii

    Andrii

    Joined:
    Sep 23, 2013
    Posts:
    136
    I've also encountered this. A Unity extension I develop is now broken because of this. Trying to figure out how to fix this.
     
    Last edited: Jul 26, 2020
  3. Andrii

    Andrii

    Joined:
    Sep 23, 2013
    Posts:
    136
    Downloaded newly released 2017.3 and it still doesn't work. I wonder if there's a workaround for this.
     
  4. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Same problem here in latest version: 2017.3.0f3.
    Haven't found any workarounds yet..
     
  5. Andrii

    Andrii

    Joined:
    Sep 23, 2013
    Posts:
    136
    I've found a workaround some time ago. It's a different approach but it works for me. Here's how I do it. When creating a control, you can pass the custom cap function instead of the default one:

    Code (CSharp):
    1. Vector3 point=Handles.FreeMoveHandle(
    2.             script.transform.TransformPoint(script.points[i].position),
    3.             script.transform.rotation,
    4.             size,
    5.             Vector3.zero,
    6.             CircleHandleCapSaveID //A name of a custom cap function
    7.         );
    Custom cap function looks like this. It just wraps around default cap function but since it receives controlID, it can pass it to current object. So after creating a control you can add its ID to some array/list to remember which control has which ID.

    Code (CSharp):
    1.     public void CircleHandleCapSaveID(int controlID,Vector3 position,Quaternion rotation,float size,EventType et){
    2.         lastControlID=controlID; //
    3.         Handles.CircleHandleCap(controlID,position,rotation,size,et);
    4.     }
    And when I have this array of IDs I can compare them to GUIUtility.hotControl to get which one is currently focused. This is how I do after control names stopped working.
     
    marplebot likes this.