Hey guys, got a fun challenge for you: Trying to load an external font at runtime and creating a TMP_FontAsset with it. So far, this is my testing code:
var font = Font.CreateDynamicFontFromOSFont("8BIT Wonder", 14);
fontAsset = TMP_FontAsset.CreateFontAsset(font, 90, 0, UnityEngine.TextCore.LowLevel.GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic);
fontAsset.name = "8BIT Wonder";
print(fontAsset.material); //for debugging, comes back as: TestMeshPro/Mobile/Distance Field (UnityEngine.Material)
GetComponent<TMP_Text>().font = fontAsset;
However, on-screen nothing changes font-wise, which makes me think the font creation didn’t work and it’s ‘falling back’ to the ‘fallback’ font. Also another thing that might be wrong is the material.
Usually TMP_FontAssets have their own ‘generated’ material but this one doesn’t. Any way to generate it?
I already asked this on the Unity Discord and someone else who tried running this code also pointed out that the font atlas is null.
I am sure that achieving this is possible, question is how.