New line commands in public strings

In my script, I set a variable to be a public string so I can edit it in the editor itself. But I noticed new line characters ( \n ) were not translated as such from the editor to the script and actually displayed the slash and the n.

When I have a private string “This is a\ntest” in a script, it prints

This is a
test

But when it is a public string and set through the editor, it displays as

This is a\ntest

Is there a way to take the literal string in the editor and convert it to the way I’d like the string to operate?

Thanks in advance for any help!

Unfortunately, the only way I’ve found to get newlines to show up when you enter them in the inspector is to type them somewhere else in a text editor or what have you using return carriages and copy/paste the text into the inspector. I’d love to know if there’s a better way, but AFAIK, Unity doesn’t escape text in the editor automatically (You could, of course, do the replacement in Awake/Start, but that’s just as onerous).

you know a little java ne? you know the script that I use to put the camera in 3rd person?

use alt-enter to print a newline in the editor textfields.

I’m not entirely sure what you mean by that, but I’ve gone a different route out of frustration and avoided strings entirely. Thanks either way for the info!

Using alt simply changes my hand tool in unity to a scale tool. Not really able to get that working

I was able to get it to work just fine. Since I presume by the use of “alt+enter” that Horsman is using Windows, I can confirm it also works on Mac using alt+return. Make sure you’re focused on the text field in the Inspector you want to edit and alt+(enter/return) away. Holding alt will trigger changing the hand tool to orbit mode (link), but that won’t affect anything unless you muck about in the Scene view.

I guess I’m just doing something wrong, then. I’ve got the cursor in the textfield in the editor and I’m holding alt and hitting enter and nothing is happening. There doesnt seem to be an alt+key command that works, except for things like alt+tab and alt+ctrl for some more unity camera commands.

ALT+ENTER

  • works on MAC
  • not on PC

I work with unity both on Mac and PC I’m running:

  • snow leopard 10.6.2
  • XP SP3

dunno about other systems

a lot has probably changed in 4 years, but I noticed when looking at the raw data in a scene or prefab

someString: here is a broken \nnewline

gets quotes around it

someString: “here is a working \nnewline”