Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    40
    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:
    40
    Moments after posting, I figured it out.

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

    Madgvox

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

    hurleybird

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

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    457
    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:
    40
    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:
    457
    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.