Search Unity

How to make an EditorGUILayout.TextField accept multi-line input in a custom inspector?

Discussion in 'Immediate Mode GUI (IMGUI)' started by hurleybird, Oct 12, 2018.

  1. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    258
    In a regular inspector:

    [TextArea(4, 100)] [SerializeField] private string message;

    Will expand a text field and let it accept multiple lines, with enter as opposed to needing \n. One the other hand:

    script.message = EditorGUILayout.TextField("Message: ", script.message, GUILayout.Height(80));

    Will also expand the text field, but does not allow for multiple line input. How can I get my custom inspector to behave the same way as the regular one and accept multi-line input?
     
  2. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    258
    Moments after posting, I figured it out.

    EditorGUILayout.PropertyField(message, GUILayout.Height(80));
     
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
  4. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    258
    No, you wouldn't. A TextArea works completely differently.
     
    NymoBasepro likes this.
  5. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    What works "completely differently"? A TextArea is a TextField that accepts multiple lines. From what you've literally said, you're looking for a TextArea (instead of a TextField specifically, which is what I was addressing in my initial post; PropertyField is a valid alternative since it takes attribute drawers into account).
     
    Last edited: Oct 17, 2018
  6. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    258
    A TextArea isn't really a TextField that accepts multiple lines. It's literally just an area you can write text into and nothing more. No graphics of any kind. It's a much lower level thing.
     
  7. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Graphics?
    I'm confused as to what you think a text field should be able to do. "An area you can write text into" seems like a pretty apt description of both a TextField and a TextArea to me.
     
  8. JoebRogers

    JoebRogers

    Joined:
    Jul 6, 2015
    Posts:
    3
    To add onto this, from the descriptions given in the Unity API documentation:

    TextField - Make a single-line text field where the user can edit a string.
    TextArea - Make a multi-line text field where the user can edit a string.
     
    lclemens and idbrii like this.