Search Unity

Carriage return in a string in the inspector?

Discussion in 'Scripting' started by MikaMobile, Oct 19, 2010.

  1. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    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?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Option-return

    --Eric
     
  3. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    Excellent, much obliged.
     
  4. Spyke

    Spyke

    Joined:
    Apr 20, 2010
    Posts:
    7
    How can i do this in windows? Alt+Enter does not work
     
  5. txblackbird

    txblackbird

    Joined:
    Mar 23, 2010
    Posts:
    36
    Ditto to Spyke. I can't get Alt+Enter to work for this either.
     
  6. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    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. )
     
  7. txblackbird

    txblackbird

    Joined:
    Mar 23, 2010
    Posts:
    36
    Thanks! Like you said, this works but I wonder why the Alt+Enter doesn't work on windows? Option+return works on my mac.
     
  8. Frank Oz

    Frank Oz

    Joined:
    Oct 13, 2010
    Posts:
    1,560
    Tried the other alt key?
     
  9. txblackbird

    txblackbird

    Joined:
    Mar 23, 2010
    Posts:
    36
    Yes, I tried both keys and neither one worked. :(
     
  10. IcyPeak

    IcyPeak

    Joined:
    Dec 1, 2009
    Posts:
    377
    EDIT: Misread OP, suggestion was already tried.
     
    Last edited: Feb 19, 2011
  11. Aerozo

    Aerozo

    Joined:
    Sep 3, 2010
    Posts:
    127
    I believe it's SHIFT+Enter in Windows
     
  12. IcyPeak

    IcyPeak

    Joined:
    Dec 1, 2009
    Posts:
    377
    Just tried it and that doesn't work =(. I'd actually like to know the solution as well if anyone figures it out =).
     
    Last edited: Feb 19, 2011
  13. DMHMikeCook

    DMHMikeCook

    Joined:
    Jul 12, 2015
    Posts:
    4
    Is there a Windows solution for this?
     
  14. Aerozo

    Aerozo

    Joined:
    Sep 3, 2010
    Posts:
    127
    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.
     
  15. muzboz

    muzboz

    Joined:
    Aug 8, 2012
    Posts:
    110
    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!
     
  16. muzboz

    muzboz

    Joined:
    Aug 8, 2012
    Posts:
    110
    GNouvelUR1, Snake-M3 and breban1 like this.