Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EditorGUI.DelayedTextField not working correctly

Discussion in 'Immediate Mode GUI (IMGUI)' started by Manu_Rivas, Mar 17, 2018.

  1. Manu_Rivas

    Manu_Rivas

    Joined:
    Mar 17, 2018
    Posts:
    1
    Hi everyone!

    I have a custom editor script to configure my game settings while I'm still developping it.
    I have the folowing PropertyDrawer wich works fine:

    Code (csharp):
    1. Rect labelPosition = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
    2. Rect fieldPosition = new Rect (labelPosition.x, position.y, 50, position.height);
    3. EditorGUI.DelayedTextField (fieldPosition, "", EditorStyles.textField);
    This is what I get:


    However, when I try to add a label to the TextField:
    Code (csharp):
    1. EditorGUI.DelayedTextField (fieldPosition, "Label" , "", EditorStyles.textField);
    This just stops working and I can't edit the TextField:



    But, according to documentation it is correct... I've tested it in Unity 5.6 and Unity 2017.3.0f3, and I get the same result in both, Does someone knows what is wrong?

    Thanks in advance.
     

    Attached Files:

  2. lokinwai

    lokinwai

    Joined:
    Feb 11, 2015
    Posts:
    174
    Your DelayedTextField is not enough place for the field, you only given 50px width but the labelWidth is wider than the field rect. The field is indeed draw from right to the left now. (e.g. from 400 back to 200).
     
  3. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    The EditorGUI.DelayedTextField return a string, which is the text than you are entering in the textfield.

    So you should use it like this:
    Code (csharp):
    1. private foat m_MyString = "";
    2. public void OnGUI()
    3. {
    4.     Rect labelPosition = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
    5.     Rect fieldPosition = new Rect (labelPosition.x, position.y, 50, position.height);
    6.     m_MyString = EditorGUI.DelayedTextField (fieldPosition, m_MyString, EditorStyles.textField);
    7. }
    Enjoy :)