Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by ZanzibarDreams · May 07, 2010 at 01:27 PM · inspectorstringtextmeshnewline

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?)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

11 Replies

· Add your reply
  • Sort: 
avatar image
23
Best Answer

Answer by duck · May 07, 2010 at 01:54 PM

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).

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZanzibarDreams · May 10, 2010 at 08:20 AM 0
Share

Thanks, that will do fine!

avatar image dingben · Dec 06, 2010 at 10:27 AM 0
Share

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.

avatar image Fehr · Oct 04, 2011 at 03:16 AM 0
Share

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.

avatar image dingben · Sep 18, 2014 at 05:52 AM 0
Share

Since you may have the $$anonymous$$ono editor up, just cut and paste 2 partial lines from any of your scripts onto the location in the line you want to split

avatar image kurtalp · Dec 02, 2016 at 08:56 AM 0
Share

it solved the bug that \r\n(it kinda works but it shows in the text ; "some text \r\n" ) i had been dealing with.

avatar image
15

Answer by michielbos · Feb 16, 2013 at 10:34 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Witchunter · Jan 12, 2014 at 01:26 PM 5
Share

Thanks for the suggestion! $$anonymous$$aybe even more intuitive, use stringname.Replace("\\n", "\n");.

This will replace literal \\n with a new line (useful if you're reading from X$$anonymous$$L for example).

avatar image noelatfalafel Witchunter · Sep 04, 2016 at 06:16 PM 1
Share

This is the cleanest variation so far, thanks!

avatar image
7

Answer by Molix · May 07, 2010 at 03:38 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZanzibarDreams · May 10, 2010 at 08:21 AM 0
Share

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

avatar image
7
Wiki

Answer by fffMalzbier · Jun 11, 2012 at 07:03 PM

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));        
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by Developer386DX · Mar 25, 2015 at 05:28 PM

In windows newline is "\r\n" so -> "hello \r\n new line"

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kurtalp · Nov 14, 2016 at 11:30 AM 0
Share

the empty space matters " ". Or it did in my problem; unity 5.3 my windows (old 7) "\r\n" did not recognized until i added the space such as " \r\n".

  • 1
  • 2
  • 3
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get this string out of this array? 2 Answers

Find the length of a string in Javascript 1 Answer

Text Mesh Scripting 1 Answer

Setting a color to selected string letters in inspector 1 Answer

"String too long for TextMeshGenerator. Cutting off characters." when doing Regex.Replace 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges