Unity Community


Results 1 to 5 of 5

  1. Posts
    8

    GUI.SetNextControlName does not change control name

    Hi everyone,

    I am writing an asset editor by deriving from the Editor class and came across the following issue.

    Example
    Code:  
    1.    private bool m_Postfix = true;
    2.    
    3.     public override void OnInspectorGUI()
    4.     {
    5.         if (Event.current.type == EventType.Layout)
    6.         {
    7.             m_Postfix = !m_Postfix;
    8.         }
    9.        
    10.         string postfix="";
    11.         if (m_Postfix)
    12.         {
    13.             postfix = "_TRUE";
    14.         }
    15.         else
    16.         {
    17.             postfix = "_FALSE";
    18.         }
    19.        
    20.         GUI.SetNextControlName("A" + postfix);
    21.         GUILayout.TextField("A");
    22.         GUI.SetNextControlName("B" + postfix);
    23.         GUILayout.TextField("B");
    24.        
    25.     }

    Now by selecting the asset for which this editor is shown and by shifting focus back and forth by clicking on the two textfields, the only two values which are logged are "B_TRUE" and "A_FALSE".
    It seems that somehow the controlname becomes fixed.

    In the actual project I am working on I have a sequence of textfields representing data in an array, next to each texfield is a delete button by which you can remove an element from the array, After I deleted an element I noticed that the focused control name (GUI.GetNameOfFocusedControl()) did not correspond to the array element that currently had focus, but rather to an array element which had been deleted.

    Does anyone have any suggestions on how to solve this problem?
    And is this actually a bug, or am I just using it wrong ?

    Any help would be appreciated.

    Cheers,

    Ben
    Last edited by BenMeijering; 07-27-2012 at 06:51 AM.


  2. Posts
    477
    I am having the same problem with 2 functions in GUI, they exclude each other, in one 2 controls with names: name1, name2... next function 3 controls with names: name3, name4, name5... there's a function which allows me to switch between the 2 functions, and when i switch the names of controls end up mixed.


  3. Location
    California, USA
    Posts
    103
    I recently reported a bug on this issue. My guess is that the control name is associated with the control's internal ControlID, and that each ControlID can only be associated with a name once. Future calls to assign a new name are ignored. This becomes an issue when you have a dynamic GUI that re-uses ControlIDs.

    See this thread for details.
    Michael Ryan
    something STRANGE


  4. Location
    Netherlands
    Posts
    32
    Is there any news on this thread?
    Or has anyone made a good workaround?
    Games and 3D environments using Unity.
    Follow me on Twitter @richardknol

  5. Developer Relations Engineer



    Posts
    65

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •