Search Unity

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

Discussion in 'UGUI & TextMesh Pro' started by subatomic, Feb 28, 2016.

  1. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    Hi, I have a class I wrote GameFont.cs, which uses an input bitmap to output a Custom Font "MyFont.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
     
    Last edited: Mar 4, 2016
  2. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    Example C# code showing how to create a Unity Custom Font using source bitmap.
     

    Attached Files:

    Last edited: Mar 4, 2016
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    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();
     
    subatomic likes this.
  4. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    This totally worked. Nice.
    Code (CSharp):
    1. Font font = AssetDatabase.LoadAssetAtPath<Font>( font_outputNamePath );
    2. if (!font)
    3. {
    4.    font = new Font();
    5.    AssetDatabase.CreateAsset( font, font_outputNamePath );
    6. }
    7. font.name = font_outputName;
    8. font.material = material;
    9. font.characterInfo = charInfos;
    10.  
    11. AssetDatabase.SaveAssets();
    12. AssetDatabase.Refresh();
     

    Attached Files:

    Last edited: Apr 13, 2016
    IzzySoft likes this.