Carriage return in a string in the inspector?

The short version: Is it possible to put a carriage return in a string variable whose content is specified in the inspector?

The long version: In my current project I have an array of different strings that are pulled into a guiText element. These strings are brief descriptions of items the player can equip (iron sword +2, blah blah blah) that are usually just a line or two long. The tricky thing is, I’d like to be able to just type these descriptions into the inspector, but some of them need to have carriage returns in them since they are more than one line long, and GUIText/TextMeshes don’t have any built in line wrapping.

If I set the text of a GUIText object or TextMesh via scripting, I can insert carriage returns via the special character \n. But if I type \n into the inspector, Unity doesn’t evaluate it as a carriage return, and just prints it out! Arg!

Any ideas?

Option-return

–Eric

Excellent, much obliged.

How can i do this in windows? Alt+Enter does not work

Ditto to Spyke. I can’t get Alt+Enter to work for this either.

I know this is going to sound like overkill… In a text editor, type out everything that you want… returns and all, copy and paste it into the inspector. (this works on mac and pc. )

Thanks! Like you said, this works but I wonder why the Alt+Enter doesn’t work on windows? Option+return works on my mac.

Tried the other alt key?

Yes, I tried both keys and neither one worked. :frowning:

EDIT: Misread OP, suggestion was already tried.

I believe it’s SHIFT+Enter in Windows

Just tried it and that doesn’t work =(. I’d actually like to know the solution as well if anyone figures it out =).

Is there a Windows solution for this?

Easiest way to do it these days is by marking the string with the [Multiline] attribute your script.

If you can’t do that I guess the next best way is to copy + paste from notepad.

It doesn’t even work for me if I copy and paste from Notepad++ or normal Notepad.

How does one achieve the carriage return in a String field in the Inspector on Windows?

SURELY there is a way!

I found a good solution at this thread:

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;

3 Likes