Search Unity

Question Font import inconsistency based on selected assets

Discussion in 'Editor & General Support' started by SomeGuy22, Jun 6, 2022.

  1. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    A subtle font issue started plaguing my project after a Unity crash and I've finally discovered the cause. To start, this is what my font looks like before the crash (on a built game)



    And after the crash it looks like this:



    Small change, but the font definitely has a higher weight and comparing it and other lines in Photoshop showed it to be true. So what changed?

    After an unfortunate session of trial and error I had narrowed the problem to font import. These are my font files:



    And you'll notice the "References to other fonts in project" list shows related Fonts. I navigated to Niramit-Medium which is the font used here and found that it had 3 references. That's weird I thought since it should be referencing all of those other files right? I hit reimport and found that the list grew to grab a whole bunch of others but still not all. This was the case for the other Niramit files as well.

    The issue was still present though so it seems like adding these references didn't do much. Since I suspected corruption I selected all Niramit files and hit reimport on all at the same time. To my surprise, the font went back to normal!

    Upon closer look, this is what happened:



    The references list for Niramit-Medium is empty. That is what fixed the problem. And it became empty by selecting all Font files and hitting reimport rather than selecting them one at a time. So it appears as though the Unity crash caused some sort of reimport where it gathered up those references for Niramit-Medium and that resulted in the change.

    So now I have 2 questions:
    1. What the heck?! Why does the references list change depending on how many font files I select? Is it due to the other Niramit files not entering the asset database yet so Niramit-Medium couldn't find them? If so that would be something like a circular dependency and I have no clue why it works like that.
    2. Why does this references list change how my font looks even without italics or bold? What is it supposed to do exactly? And is there a way to ensure that it never grabs references again just in case I can't reproduce the results using this trick? If acquiring the references to all fonts in the family is the "correct" way, that means I've gotten used to the incorrect rendering of Niramit-Medium and would have to find a way to rectify that in future projects.
    Any insight into this is appreciated. It seems like a bug since the references list should either be one way or the other on every reimport, yet the results are inconsistent when I select more than one file. If this is intended then it could cause a lot of confusion when a font gets added before another and is unable to find the correct fallback due to the order of import.
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Wanted to provide an update on my progress here. My understanding of the references list is that it acts as a "hotswap" of sorts so that if you use the italics or bold feature on a Text element it will actually switch fonts behind the scenes if the current font has a reference for that setting, i.e. italic reference will be used instead. Who knows what gets mapped to what though since it doesn't tell you. Without references, it might be the case that Unity just squishes the font to make it match different styles like slanting it for italics. That would explain the inconsistency I saw with and without references.

    My solution in more recent projects is to just make the jump to Text Mesh Pro and use that for all of my UI texts. TMPro requires you to create TMP FontAssets which provide greater control over references since they are manually specified rather than automatically generated like I found out in my original post.

    Using TMPro and the new Font Assets have provided better consistency with Font rendering so I would highly recommend it, but it still feels a bit "tacked on" and doesn't quite flow as well with other Unity components. Some examples being the old Shadow and Outline UI elements that no longer work on TMPro. I will use TMPro for everything going forward but it requires a bit of getting used to, and replacing old Text elements with TMPro is also a bit tedious but worth it for the added control. Another benefit is higher resolution text in the Editor and new gradient features too, so I'm glad I switched.