Search Unity

Font Atlas being applied as a texture on each TextMeshPro character (among other)

Discussion in 'UGUI & TextMesh Pro' started by laurentdelrey, Dec 15, 2020.

  1. laurentdelrey

    laurentdelrey

    Joined:
    Feb 22, 2018
    Posts:
    3
    Hey guys,

    I generated a font atlas for a custom font that I'd like to use with TextMeshPro within a prefab.

    Along with the fact that the object doesn't show up in the Game View, I'm struggling with the Font Atlas being applied as a texture on each character (ie. screenshot attached).

    I also recorded a short screencast to provide as much context as I can.

    I tried to:
    - Create a different Material Preset
    - Use a different font
    - Re-create a TMP object
    - Closing and re-opening the project

    Unity Version: 2019.3.12f1

    Does anyone have any thoughts that could help me figure this out?
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Let's first go over the core aspects of a font asset as it related to characters, glyphs and atlas texture.

    The Character Table contains the individual character as seem below.

    upload_2020-12-15_15-27-49.png

    Character are assigned a Unicode code point which is how we reference them in a string or text object input box. Characters have a Glyph ID which references the glyph which is the visual representation of this character and contained in the Glyph Table as seen below.

    upload_2020-12-15_15-32-19.png

    The Glyph Table contains the glyphs or visual representation of those characters. These glyphs are what is contained in the atlas texture. A glyph may be referenced by multiple characters.

    A Glyph contains a GlyphRect which indicates where in the atlas texture the glyph is located. The Glyph also contains the GlyphMetrics which defines how the glyph will be positioned relative to the origin / advance of the previous glyph and baseline.

    With that out of the way, when you are trying to create a custom font asset using some atlas texture, you will need to manually create / add new glyphs in the Glyph Table. You will need to define their glyph rects and glyph metrics.

    Next, you will need to create / add characters in the Character Table and assign them a Unicode code point and glyph ID so they point to the correct glyph.

    In terms of why the "7" is showing the whole texture, it is likely because you didn't define the glyph, glyph rect and glyph metrics for this glyph.

    Note: That you need to make sure you select the correct shader for the material used by this font asset. Use an SDF shader for SDF textures and a TMP Bitmap shader for those bitmap textures.
     
    ringwraith likes this.
  3. laurentdelrey

    laurentdelrey

    Joined:
    Feb 22, 2018
    Posts:
    3
    Thank you so much, Stephen. This is super clear and it makes a lot of sense!

    It feels like a lot of work for what I'm trying to achieve. I may just try to use this asset.

    If you know any other way that would let me skip the step where I'd need to define their glyph rects and glyph metrics, I'll take it :)