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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

TextMesh Pro Set the Glyph Table parameters from the script

Discussion in 'UGUI & TextMesh Pro' started by ysalpha, Aug 23, 2022.

  1. ysalpha


    Feb 2, 2017
    Is it possible to adjust the Glyph Table from the script after generating the SDF?
    When we re-generate the SDF, the Glyph Table parameters that we have adjusted will be reset.
    Every time I generate an SDF, I have to re-set the Glyph Table values from Inspector, which is very difficult.
  2. Stephan_B


    Unity Technologies

    Feb 26, 2017
    The ability to preserve "edits" to the various font asset tables has been requested in the past. This makes a lot of sense to me so definitely something to add at some point.

    In terms of making those adjustments in code, the TMP_FontAsset.glyphTable property is public where as such, you should be able to modify individual glyphs to reapply your custom changes. Be mindful these values are relative to the sampling point size.
  3. ysalpha


    Feb 2, 2017
    I was able to change the glyphTable parameter with the following code.

    Code (CSharp):
    1. char chr = 'A';
    2. uint unicodeNumber = System.Convert.ToUInt32( chr );
    3. var character = tmpFontAsset.characterTable.Find( x => x.unicode == unicodeNumber );
    4. if( character != null )
    5. {
    6.     var glyph = tmpFontAsset.glyphTable.Find( x => x.index == character.glyphIndex );
    7.     if( glyph != null )
    8.     {
    9.         glyph.scale = 10.0f;
    10.     }
    11. }