Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

Discussion in 'Extensions & OnGUI' started by hurleybird, Oct 12, 2018.

  1. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    38
    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:
    38
    Moments after posting, I figured it out.

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

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    450
  4. hurleybird

    hurleybird

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

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    450
    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 at 12:44 PM
  6. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    38
    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:
    450
    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.