4.6b20 how to add a line break in a text widget by script

Hello,

I read my localized text from a CSV file. Each text entry, no matter how long, is a single line.

I then set the text on a Text component by script.

My CSV line is: BIO_TEXT_ID, Age: 27 Gender: male Place of Birth: Austin

When the menu is displayed, I want my text widget to display the text on separate lines:
Age: 27
Gender: male
Place of Birth: Austin

I tried doing: BIO_TEXT_ID, Age: 27\nGender: male\nPlace of Birth: Austin

But the \n is displayed with no line break.

Any idea how to do this?

Thanks!

After some experimentation, I found a solution:

string characterTextString = LocalizationManager.Instance.getText(BIO_TEXT_ID);
characterTextString = characterTextString.Replace(ā€œ\nā€, System.Environment.NewLine );
characterText.text = characterTextString;

The 2 slashes in ā€œ\nā€ ARE important.
The characterText will now display correctly the line breaks :slight_smile:

2 Likes