Changing a *.fontsettings file invalidates all inspector locations where that font is used.

Hi, I have a class I wrote GameFont.cs, which uses an input bitmap to output a Custom FontMyFont.fontsettings” file. I can then drag this file onto any Font slot in the UI for example. However, when I regen the fontsettings file, every UI which has the Font set on it becomes “Missing (Font)”.

I did check the MyFont.fontsettings.meta file, but the GUID isn’t changing when MyFont.fontsettings is regenerated… It’s almost like it is a GUID problem though… Does anyone know whats going on, and how I can avoid it? I’d like to be able to regen the font and have the UI simply update, rather than go Missing

I saved off a copy of MyFont.fontsettings and ``MyFont.fontsettings.meta, regenerated, then compared:

MyFont.fontsettings:
md5sum matches between old and new

MyFont.fontsettings.meta:
diff ../bak/MyFont.fontsettings.meta MyFont.fontsettings.meta
3c3
< timeCreated: 1456701320
---
> timeCreated: 1456701390

Example C# code showing how to create a Unity Custom Font using source bitmap.

2538078–176228–GameFont.cs (6.42 KB)
2538078–176229–DetectChanges.cs (1.94 KB)
2538078--176230--hud.png

check if the Asset exists 1st in ./Assets/… with AssetDatabase.LoadAssetAtPath(…, …);

if it return null… then AssetDatabase.CreateAsset(…);

else make changes to the already loaded asset.

and then call …

AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

1 Like

This totally worked. Nice.

Font font = AssetDatabase.LoadAssetAtPath<Font>( font_outputNamePath );
if (!font)
{
   font = new Font();
   AssetDatabase.CreateAsset( font, font_outputNamePath );
}
font.name = font_outputName;
font.material = material;
font.characterInfo = charInfos;

AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

2594664–181588–GameFont.cs (8.53 KB)

1 Like