• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Steven-Walker · Dec 08, 2010 at 05:57 PM · inspectortextareawrapwordwrap

EditorGUILayout.TextArea Wrap

I have a custom inspector with a TextArea field, but it does not wrap, which is a real pain to work with. I've tried changing the skin settings, but no luck. I'm trying to do the following during OnInspectorGUI, but to no avail:

var skin : GUISkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
skin.textArea.wordWrap = true;

I've also tried:

function OnGUI() {
    if(GUI.skin.customStyles.Length > 0)
        GUI.skin.customStyles[0].wordWrap = true;
}

But no luck either.

Any suggestions?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Dec 08, 2010 at 11:55 PM 1
Share

If you're using EditorGUI.TextArea then the dos indidate that you'll want to modify EditorStyle.textField, not GUI.skin.textArea.

http://unity3d.com/support/documentation/ScriptReference/EditorGUI.TextArea.html

2 Replies

· Add your reply
  • Sort: 
avatar image
11
Best Answer

Answer by Steven-Walker · Mar 31, 2011 at 12:00 AM

As yoyo suggested, setting the attribute on EditorGUI.textArea fixes the problem. I add the following line of code and it works:

EditorStyles.textField.wordWrap = true;
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pctroll · Apr 05, 2014 at 11:08 AM 1
Share

Great! This just worked

avatar image Tiki · Jul 04, 2014 at 01:07 PM 0
Share

Old Post I know, but thx, made this a quick search.

keywords: unity text area word wrap - first answer

avatar image adamk33n3r · Apr 26, 2017 at 09:40 PM 0
Share

This is so weird. You need to set this even if you're wanting to make textAreas word wrap. Setting EditorStyles.textArea.wordWrap to true doesn't work but this does. What???

avatar image Spacew00t · Aug 03, 2018 at 05:30 PM 1
Share

Old post, but it's the first result on google, so I'll add some clarification. Setting this isn't always enough:

 EditorStyles.textArea.wordWrap = true;

You also have to specify the style when you're using the TextArea method:

 EditorStyles.textArea.wordWrap = true;
 value = EditorGUILayout.TextArea(value, EditorStyles.textArea);

This seems obvious in hindsight, but my sleepy brain just got frustrated that this solution wasn't working. Hope it helps someone!

avatar image Bunny83 Spacew00t · Aug 03, 2018 at 06:28 PM 2
Share

Uhm, by default it is using this style. It literally uses it: Though i wouldn't recommend messing up the built-in styles. Just create your own style out of the built in and use that ins$$anonymous$$d.

 GUIStyle myTextAreaStyle = new GUIStyle(EditorStyles.textArea);
 // ...
 myTextAreaStyle.wordWrap = true;
 value = EditorGUILayout.TextArea(value, myTextAreaStyle);


avatar image SolidAlloy Bunny83 · Oct 30, 2020 at 10:09 AM 0
Share

Or even better:

 GUIStyle myTextAreaStyle = new GUIStyle(EditorStyles.textArea) { wordWrap = true };
avatar image
5

Answer by adbourdages · Feb 13, 2015 at 05:32 PM

Here is a simple way to apply word-wrap to a multi line string variable (here applied to a Comment component I use to leave comments in the editor).

 public class Comment : MonoBehaviour {
    [SerializeField]
    [TextArea(5, 3)]
    string comments;
 }

Here is what it looks like: linky link text

It was taken from the UnityEngine.UI.Text component.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lumos · Jun 28, 2015 at 03:31 PM 0
Share

Thanks! Replacing all $$anonymous$$ultiline attributes with TextAreas seems to have no drawbacks, and works brilliantly.

avatar image Edy · Jan 22, 2019 at 11:33 PM 0
Share

This is the best solution, definitely! Other solutions have these drawbacks: height doesn't expand and/or no scrollbar.

avatar image hadynlander · Jan 14, 2020 at 01:55 AM 0
Share

This is absolutely the best answer; clean code, no custom editors required, automatic implementation of scrollbars, specifically targets the field(s) you want it to apply to, etc. Thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to render a GUI.TextArea into a Texture ? 1 Answer

How to access one class instance in editor script? 1 Answer

[SerializeField] instead public 1 Answer

Inspector button for custom class 1 Answer

Weird results when rotating a GameObject 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges