Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro OS Font

Discussion in 'UGUI & TextMesh Pro' started by aortega_ea, Sep 10, 2019.

  1. aortega_ea

    aortega_ea

    Joined:
    Feb 19, 2019
    Posts:
    7
    In Unity 2018.4 and TMP 1.4.1 if I create a font with Font.CreateDynamicFontFromOSFont and feed it to TMP_FontAsset.CreateFontAsset, it never adds any characters to the atlas. The same OS font with a regular Text component works fine.

    What am I missing?
     
  2. aortega_ea

    aortega_ea

    Joined:
    Feb 19, 2019
    Posts:
    7
    FontEngine.LoadFontFace returns 85. If these are the same error codes as FreeType this is Invalid_Stream_Operation.
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The CreateDynamicFontFromOSFont does not include the font data which is necessary.

    Instead use the following:

    Code (csharp):
    1.  
    2. // Get the file path of all OS fonts.
    3. string[] fontPaths = Font.GetPathsToOSFonts();
    4.  
    5. // Create new Font using one of those paths.
    6. Font osFont = new Font(fontPaths[124]);
    7.  
    8. // Create new font asset using this OS font.
    9. TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(osFont);
    10.  
     
  4. aortega_ea

    aortega_ea

    Joined:
    Feb 19, 2019
    Posts:
    7
    When I try this, in an empty project, the font returned by the Font constructor is completely empty, except for the name (characterInfo length is zero). Tested in 2018.4.8f1 and 2019.2.5f1. Bug?
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This returns a font that only includes the source font file that TMP needs to generate a font asset from. This does not create a Unity font for use with UI Text.
     
  6. aortega_ea

    aortega_ea

    Joined:
    Feb 19, 2019
    Posts:
    7
    I was just missing the TMP Essential Resources. This works, thank you very much.
     
    Stephan_B likes this.
  7. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89

    Hi,Stephan_B, i found that, if the font is created with fontName, then the fontAsset created was null.
    but if the font is created with path, then the fontAsset is correct.
    Why??
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That is the expected behavior.

    When I made the change to the Font constructor, I kept the existing implementation with the fontName and added the new functionality when using a path.
     
  9. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    thank you.Does this mean that i can't use fontname to create TMP_FontAsset?? The normal FontAsset can be created with fontname.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You cannot use the font name. You have to use the font file path.

    When support for Dynamic OS Font Assets is introduced in the next preview release, you will be able to reference system font by their Family and Style names.
     
  11. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    thank you very much!