- Home /
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?
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
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;
Old Post I know, but thx, made this a quick search.
keywords: unity text area word wrap - first answer
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???
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!
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);
Or even better:
GUIStyle myTextAreaStyle = new GUIStyle(EditorStyles.textArea) { wordWrap = true };
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: link text
It was taken from the UnityEngine.UI.Text component.
Thanks! Replacing all $$anonymous$$ultiline
attributes with TextArea
s seems to have no drawbacks, and works brilliantly.
This is the best solution, definitely! Other solutions have these drawbacks: height doesn't expand and/or no scrollbar.
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
Follow this Question
Related Questions
Is it possible to render a GUI.TextArea into a Texture ? 1 Answer
Inspector Property Names Documentation.. 1 Answer
Why aren't public variables showing up? [Solved] 1 Answer
Custom Inspector: Using 'serializedObject' to access inherited members 1 Answer
Components added programatically - visibility in inspector 1 Answer