- I have txt and btn.
- btn will use the UI’s OnClick event to change txt.text’s string: “Hello\nWorld”
- Ensure “parse escape characters” is checked (and rich text too, just in case).
- Start >> Click btn >> The result is the literal of @“Hello\nWorld”
- If I uncheck “parse escape chars” and check it again (while playing), the txt str will jump back to what’s expected.
Is this string in code or contained in a public string field in the inspector?
Most of the time, the string being provided to the text object gets escaped by Unity. This can easily be verified stepping through the code an inspecting the string where you will end up with a "" and “n” instead of char(10).
The Parse Escape Characters only affects text input in the Text Input Box and not when the text comes from a string.
Let me know the result of the above string inspection.
P.S. I am at the Airport to fly over to Europe, so most likely I won’t be able to reply until I get there as Internet Connections on flight is usually horrible.
public string in the inspector – it’s just a Unity UI event. In the Button’s OnClick event, I drag a TMPro txt and change it’s string~
The Unity is escaping the text. You will need to account for this an use string.replace to remove the additional / inserted "". See the following thread .
P.S. As per my previous comments about this in other threads. This automatic escaping of characters in text fields in the editor is very confusing as having a string in code with “\n” is parsed as linefeed whereas the same text in a public string edited in a text field ends up being “\n” . This is something I have discussed with the Editor team.