Search Unity

Bug Custom Font Set in TMP - Text (UI) Component Swapped with Default Font Randomly

Discussion in 'UGUI & TextMesh Pro' started by pako, Jul 14, 2022.

  1. pako

    pako

    Joined:
    Nov 21, 2012
    Posts:
    111
    Hi,

    The problem happens with Unity 2021.3.5f1 LTS and 2021.3.6f1 LTS, and TextMeshPro 3.0.6.

    I have several elements in my UI with TMP Text Components. Everything was working fine for many weeks (I believe it was before I upgraded to Unity 2021.3.5f1 LTS). Yesterday, I noticed that the custom font I had set in the components, was being swapped, during Play mode, with the default TMP font "out of the blue", and for no apparent reason. In Edit mode, there's no problem, the fonts are set correctly. Moreover, the "swap" doesn't happen all the time. Sometimes, there's no swapping, but quite frequently, the fonts are swapped, and when they are swapped, they are not swapped for all the components using that font.

    I re-imported and re-created the custom fonts, and made sure that the fonts are in a Resources folder.

    The only change that I can probably relate to (besides upgrading from Unity 2021.3.4f1 LTS to Unity 2021.3.5f1 LTS), is that I was using the Canvas as a prefab, and I unpacked it a couple of days ago. I did just an "unpack, not "unpack completely", but the UI elements with TMP Text, which are children of the Canvas, were not a prefab themselves anyway.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Does this issue occur in Play mode or in a build?

    If this occurs in a build, double check to make sure your font assets are included in the build.

    Font Assets are expected to be located in the location specified in the TMP Settings which by default is "Resources/Fonts & Materials/...". Double check to make sure that is still the case for you and that your font assets are located in the specified location.
     
  3. pako

    pako

    Joined:
    Nov 21, 2012
    Posts:
    111
    As I said in my post "... and made sure that the fonts are in a Resources folder".

    EDIT: I double-checked and all the font assets are indeed in "Resources/Fonts & Materials/ as set in TMP Settings.

    I haven't noticed the problem in a build, but it's definitely happening in Play mode. It seems to me that when I first start Play mode, at least one of the fonts gets swapped. Then when I stop Play mode and start it again, the fonts are OK. Then after a while (probably after compiling a script, or making some changes in the scene - not quite sure), and starting Play mode again, the font gets swapped again, in what seems like a cycle of "swap font, fonts OK, etc.".
     
    Last edited: Jul 14, 2022
  4. pako

    pako

    Joined:
    Nov 21, 2012
    Posts:
    111
    I did some more testing to provide you with some more info. In the Start Menu, there are 3 labels with TMP. Two of them use the same outline font size 72, and the 3rd one the same family outline font but size 120. Here's what happens:
    • I load the project and start play mode: All 3 labels show the default font, which I have set in TMP Settings to be the same font family as in the labels inside the scene, but non-outline.
    • I stop play mode and restart it. All labels show the correct outline font.
    • I repeat start/stop play mode 2 more times, and the fonts display correctly again.
    • I close the project, and then re-open it, and repeat the above steps. The results are the same, i.e. only the first time after opening the project, the default font is swapped in all 3 labels.
    • I then make a small scene change and save it (without first closing and re-opening the project).
      • I repeat the start/stop of play mode 3 times, and no problem. All 3 labels show correctly the outline font.
    • I then make a small script change (added a new empty line) to force compilation.
      • I start play mode, and this time the 2 labels with the 72-size font display the correct outline font. However, the 3rd label with the 120-size font displays the default font.
      • I start/stop play mode 2 more times, and this time all 3 labels display the correct outline font.

    I hope this helps.