- Home /
Is it possible to request a line break inside the Inspector?
I have a tooltip system and to avoid text spilling off the side of its backdrop, I need to occasionally insert line breaks. Since each object that has a tooltip has a tooltip script attached, it also has a public string where I can change what that tooltip is.
I'm using a stylistic 3D interface, so I'm using 3D text; thus there is no automatic word wrap or anything of the sort.
I tried inserting the standard \n for a line break but it appears that this doesn't work for text entered in the inspector. Does this mean I'm going to have to write an entire script just to implement line breaks? Seems a bit convoluted, so I figured I'd ask around for alternatives.
Answer by Jason B · Oct 13, 2011 at 06:40 PM
Guess I'll just answer my own question since I figured out a workaround. Not a very convenient one, though. Looks like you have to type your line breaks out in Notepad and copy/paste them into the inspector. Only way to get it to work.
Hopefully the Unity team looks into this.
Yeah, this is an issue with windows build of unity. However on $$anonymous$$ac it is possible with the 'alt/option'-enter to do a new line
Answer by Eric5h5 · Sep 30, 2011 at 08:23 PM
Type alt/option-return.
Doesn't seem to work. Holding alt toggles the camera mode in the scene view, and pressing enter while holding it causes Windows to make its little "oops, can't do that" sound effect.
Answer by muzboz · Jan 19, 2019 at 02:55 AM
I found a good solution at this thread: https://answers.unity.com/questions/1299564/how-to-create-new-line-in-string-from-inspector.html
Add the TextAreaAttribute to your string variable, and the Inspector will now provide you with a larger text entry box that allows you to just use the Enter key to make carriage returns. Yay!
eg:
[TextArea]
public string myString;
Answer by jahroy · Nov 11, 2011 at 02:03 AM
You can also use an escape sequence in the Inspector and replace it in your script.
We use three under-scores to represent a newline.
When you display the string to the screen you use this:
Debug.Log(someString.Replace("___", "\n"));
Sorry this came a little late...
It's not a bad idea, I don't $$anonymous$$d if it's late. I was thinking about doing this anyways because our current tooltip system needs to be rewritten a little bit to where I'm going to have to acknowledge line breaks anyways in the script. :)
I'm sure you're aware of this, but I'll throw it out there anyways...
GUIStyle has a wordWrap property:
http://unity3d.com/support/documentation/ScriptReference/GUIStyle-wordWrap.html
I stated in the question, I'm not using GUIs. I'm using an assortment of textured planes with 3D Texts (I find the overall effect much more pleasant and speedy than the GUI system built into Unity).
Right on.
I was adding that more for the next guy who stumbles onto this fabulous question...
Your answer
Follow this Question
Related Questions
Line Break Within Inspector GUIText 0 Answers
Making newline ( \n ) in inspector 11 Answers
How to extend TextMeshProUgui to show new public in the inspector 0 Answers
How do I create a JavaScript class that creates an object with viewable variables in the inspector? 3 Answers
Why is my class hidden in inspector with C# and not JS? 1 Answer