Search Unity

TextMesh Pro Unwanted behaviour when characters "\u" are in the text.

Discussion in 'UGUI & TextMesh Pro' started by Lili_Chan, Mar 2, 2019.

  1. Lili_Chan

    Lili_Chan

    Joined:
    May 13, 2018
    Posts:
    4
    Greetings.

    When displaying text on screen, with TextMesh Pro, if the text contains those two characters following each other: "/u" weird things start to happen.

    If, for instance, you display a folder or file path in the text looking like this:
    "C:\Unique Path\Application\VeryOriginalExample.exe"
    "The modification is wanted\unwanted. Choose the correct answer."

    As soon as the font is altered (made bold, italic, rescaled, or anything), the text displayed for those examples changes to:
    C:□th\Application\VeryOriginalExample.exe
    The modification is wanted□ted. Choose the correct answer.

    See the problem? This white square symbol, and the letters absorbed in a black hole? Yup, that's what bothers me.

    In order to avoid the problem, you have to double the antislash:
    "C:\\Unique Path\Application\VeryOriginalExample.exe"

    The real problem is: if you write this text from code, and not in the UI, you already type a double antislash, but once the text is updated with your content, any change on the font will alter the text.
    The issue doesn't occur with usual text, only with TextMesh Pro.

    I suppose the \u is used as a tag, or something.

    Hope my explanation was clear enough. Ask if you need more information or details.

    Why is it doing that? And more importantly, what can I do to fix it?

    Thanks.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The C# convention for Unicode Character Escape Sequence is as follows: To access UTF16 characters you would use \u followed by 2 hexadecimal pairs and for UTF32 \U followed by 4 hexadecimal pairs.

    So when trying to reference a url in a string, you must use escape it such as : "C:\\Unique path".

    When trying to set the text in the inspector, the behavior is trickier as Unity will escape these control characters without the user's knowledge. For if you create a private string field and use "\u03a9" to display the Greek letter Omega, it will work as expected. However, if you create a public string field and type in this field "\u03a9" the Editor escapes the sequence and you get "\\u03a9" or these 5 distinct characters.

    See the following thread and post of mine with additional details.
     
  3. Lili_Chan

    Lili_Chan

    Joined:
    May 13, 2018
    Posts:
    4
    Thank you very much, @Stephan_B !
    That absolutely makes sense to me, and I stand by your point when you say you would like to revise this.
    Having no better way, so far, in my particular case, I will dynamically switch every \ with /, before displaying the string in a text on screen.

    Looking forward for your revision in the future, as it seems more logical to me.

    Thank you again for your answer.

    Edit: Voila! Done already, works wonders.
     
    Last edited: Mar 2, 2019
    Stephan_B likes this.