Search Unity

TextMesh Pro OS Font

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by aortega_ea, Sep 10, 2019.

  1. aortega_ea

    aortega_ea

    Joined:
    Feb 19, 2019
    Posts:
    5
    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:
    5
    FontEngine.LoadFontFace returns 85. If these are the same error codes as FreeType this is Invalid_Stream_Operation.
     
  3. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,187
    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:
    5
    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

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,187
    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:
    5
    I was just missing the TMP Essential Resources. This works, thank you very much.
     
    Stephan_B likes this.