x


Making newline ( \n ) in inspector

I am making some localized tips to be displayed when my player enters an area. These tips are displayed over the characters head.

I have a gameObject with an exposed string, so that I can place tips around my scene, and enter the message I want to have displayed. The string is then passed forward to a TextMesh when the character collides with the tip.

The problem I am encountering is entering new line ( \n ) into the string in the inspector. The escape character is shown in inspector but is left out in game ( the '\' is gone, but not the 'n'). I have tried entering \n by using alt + enter ( as suggested in the reference manual ). But it doesn't seem to work.

Has anyone managed to input newlines through the inspector? (how the hell did you do that :o?)

more ▼

asked May 07 '10 at 01:27 PM

ZanzibarDreams gravatar image

ZanzibarDreams
273 10 12 22

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

This appears to be a bug in the windows version of Unity. You can't manually type a return character into an inspector text field, and \n doesn't work.

The only workaround for this is to copy and paste a return character (for example, from notepad).

more ▼

answered May 07 '10 at 01:54 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Thanks, that will do fine!

May 10 '10 at 08:20 AM ZanzibarDreams

I attempted to type in a Ctrl-J... and poof went the Editor... lol Do not do that! (3.1) Why did they not resolve that with version 3 ?!? Cut & Pasting text from Notepad seems to work, but painful to format to fit the scene.

Dec 06 '10 at 10:27 AM dingben

That worked a treat. Thanks for that.

Just to clarify for others, there isnt any phisical character that appears in the inspector. . . simply copy and paste text (including blank lines) from a text field.

Oct 04 '11 at 03:16 AM Fehr
(comments are locked)
10|3000 characters needed characters left

You can also create a custom inspector that uses a TextArea, rather than a TextField, for the string in question.

more ▼

answered May 07 '10 at 03:38 PM

Molix gravatar image

Molix
4.8k 16 27 66

I am on a tight deadline, but I'll look in to this more! thanks

May 10 '10 at 08:21 AM ZanzibarDreams
(comments are locked)
10|3000 characters needed characters left

Picked up Molix idea :

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(TextMesh))]
public class TextEditor : Editor {
    public override void OnInspectorGUI () {    
        this.DrawDefaultInspector();    
        TextMesh current_target = target as TextMesh;

        EditorGUILayout.LabelField("   Text:", "");

        current_target.text = EditorGUILayout.TextArea( current_target.text,GUILayout.MaxHeight(500f));     
    }
}
more ▼

answered Jun 11 '12 at 07:03 PM

fffMalzbier gravatar image

fffMalzbier
320 3 5 8

(comments are locked)
10|3000 characters needed characters left

Not sure if this question is still alive, but I found another workaround to put a newline into a string in the inspector:

function Start () {
    stringname = stringname.Replace("NEWLINE","\n");
}

Just place NEWLINE in your string, or replace the NEWLINE in the script with something else.

more ▼

answered Feb 16 at 10:34 PM

michielbos gravatar image

michielbos
51 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x467
x419
x100
x8

asked: May 07 '10 at 01:27 PM

Seen: 6804 times

Last Updated: Feb 16 at 10:34 PM