Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Empty spaces within TextMeshPro UGUI doesn't show up?

Discussion in 'UGUI & TextMesh Pro' started by longarm123, Dec 18, 2018.

  1. longarm123

    longarm123

    Joined:
    Mar 9, 2013
    Posts:
    8
    Hello I added an empty " " after a word and it doesn't show up. For example ([word] ) . Where there is a singular space after the word. It counts it as null I assume.

    This also happens when I have just " " as text for UGUI which shows as null as well.

    Is there a way to change it where an actual space shows up on screen?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    You mean at the end of a line?

    Spaces do not typically contribute to text alignment (ie. they are ignored at the end of a line). Tab and \u00A0 (non breaking space) are not ignored.
     
  3. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    56
    we are using nbsp but still its lost in wrapping of the text. &nbsp is converted using htmldecode.
    [Determine the value of n for the         disc from the]
     
    Last edited: May 8, 2020
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Why are you injecting a bunch of spaces in the text?

    Are you trying to insert some graphic / sprite in the text?
     
  5. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    56
    Yes and graphic is overlapped in the empty space and I can't include this graphic with same text. Its dynamic text so position of space might change.
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Why are you not using sprites in the text coming from a Sprite Asset?

    Sprites in the text behave like any other character including line breaking.

    In your example, the text would change to "Determine the value of n for the <sprite=x> disc from the ..." where x is the index of the sprite you wish to display. Sprites can be referenced by index, name or unicode.

    There are several examples included in the TMP Examples & Extras that use sprites in the text.
     
  7. Umresh

    Umresh

    Joined:
    Oct 14, 2013
    Posts:
    56
    Sometimes there will be another component overlapping that space whose positions are dynamic. So there is no way for me to know if its just empty space OR there will be another component(image/text/empty) on top of this text.
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The point of using Sprites in the text is to not have to worry about any of this as the sprites will line wrap just like any other characters in the text. The spacing will also be automatic based on the sprite glyph metrics.

    Why are you not using Sprites in your text to represent those images?