TextMesh Pro OS Font

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?

FontEngine.LoadFontFace returns 85. If these are the same error codes as FreeType this is Invalid_Stream_Operation.

The CreateDynamicFontFromOSFont does not include the font data which is necessary.

Instead use the following:

// Get the file path of all OS fonts.
string[] fontPaths = Font.GetPathsToOSFonts();

// Create new Font using one of those paths.
Font osFont = new Font(fontPaths[124]);

// Create new font asset using this OS font.
TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(osFont);

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?

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.

I was just missing the TMP Essential Resources. This works, thank you very much.

1 Like

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??

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.

thank you.Does this mean that i can’t use fontname to create TMP_FontAsset?? The normal FontAsset can be created with fontname.

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.

thank you very much!