Search Unity

TextMesh Pro Characters overlay one another when displaying dynamic string

Discussion in 'UGUI & TextMesh Pro' started by Absinthe23, Feb 11, 2018.

  1. Absinthe23

    Absinthe23

    Joined:
    Feb 1, 2015
    Posts:
    16
    When using a TextMeshProUGUI and typing directly into the inspector spaces and tabs come out correctly:



    But when using a dynamically built string e.g. string1 + " " + string2 with the SetText method this happens:



    The appended string begins in the same position as the first string.

    I've tried the following:

    1. SetCharArray and using the .text property - no difference
    2. Using the space char code '\x20' - no difference
    3. Inserting many space char codes - moves the "III" text but can't accurately predict how many spaces to move it for non type-safe fonts
    4. Using a tab char code '\t' - this is unpredictable, sometimes the appended string will correctly move to after "Titan" but without any space. On words of shorter lengths it may appear to move it too far to the right, as though several tabs were used, on longer words several tabs are required to move it to the end.
    5. Various combinations of the above
    What is the correct way to display strings generated at runtime that contain spaces please?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Did you copy / paste the text for the string from somewhere? I suspect there is a Carriage Return (CR) char(13) between Titan and III.
     
  3. Absinthe23

    Absinthe23

    Joined:
    Feb 1, 2015
    Posts:
    16
    Yes that was it, thanks very much. Replacing carriage returns did the trick.
     
    Stephan_B likes this.