Creating TMP font during build runtime

Hi, I’m looking for a solution to read a .ttf file as bytes[ ] and somehow turn it into a TMPro FontAsset. I’ve spent a few hours and decided to move on to creating a TMPro FontAsset with Font.CreateDynamicFontFromOSFont in combination with TMP_FontAsset.CreateFontAsset, however I can’t seem to get that working either.

Maybe I can get access to unity source code for importing a UnityEngine.Font to use with TMP_FontAsset.CreateFontAsset? I have Unity Pro.

Hoping anyone can shed some light on this, I’d really love to have this as a feature of my product, and the end users would love it.

The Font.CreateDynamicFontFromOSFont() does not create a valid font object in the sense that it does not contain the font data.

Instead use the following as per this post .

// Get paths to OS Fonts
string[] fontPaths = Font.GetPathsToOSFonts();

// Create new font object from one of those paths
Font osFont = new Font(fontPaths[index]);

// Create new dynamic font asset
TMP_FontAsset fontAsset = TMP_FontAsset.CreateFontAsset(osFont);
1 Like

Thanks a bunch! it works! :smile:
I think I got confused when the new Font(string) Intellisense was asking for a “name” but looks like it uses a file path?

Correct.

P.S. Check out the following post about Dynamic OS Font Assets which will be available in the next preview releases.

6888473--805379--upload_2021-2-28_22-32-35.png

thanks for the update, I’m curious if that will fix the following issue that I noticed:

Only certain fonts can be used with this method of OSFonts. I’m not sure why.
How can I allow fonts that I install to show up? I’m trying to use fonts that are listed as Free for Commercial use.

**** Nevermind, I think i figured that out.
Only fonts with Font file names can be used! it works great again! :stuck_out_tongue: