Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug (Urgent) Fonts loaded from asset bundles do not work after upgrading from 2020.3.18 to 2020.3.27f1

Discussion in 'UGUI & TextMesh Pro' started by aaversa, Feb 5, 2022.

  1. aaversa

    aaversa

    Joined:
    Sep 5, 2016
    Posts:
    41
    This issue is truly inexplicable. We have two code paths in our game to load resources, depending on the target platform. One is Resources.Load<>, the other loads from AssetBundles. We of course have fonts in AssetBundles as well.

    After updating our Unity version to 2020.3.27f1, fonts that are (1) loaded from AssetBundles, and (2) swapped during runtime in a TMPro object, do not render. They are invisible. Inspecting the objects gives errors like this:

    https://cdn.discordapp.com/attachments/160444359815331841/939612567259734046/unknown.png

    This happens with all of our fonts. I'll emphasize the details here using an example font asset, let's call it "TestFont".

    1. If I make a TMProUGUI object in a scene, and run the game, TestFont always renders correctly.

    2. If I load TestFont at runtime via Resources.Load<>, put it into a dictionary, and then find a TMProUGUI object in the scene and swap its font, it works fine.

    3. If I do step (2) but TestFont is loaded via an AssetBundle, it does not render.

    4. This worked completely fine in 2020.3.18.

    5. This behavior happens regardless of platform. i.e. AssetBundles on PC or Nintendo Switch display this behavior, but Resources.Load works either way.

    My asset bundle loading code is working fine and hasn't changed during the version update. It correctly reports that each asset has in fact been loaded as expected. None of them are null, all names are correct, etc.

    I'm pretty desperate because this is a complete blocker to all of our current work. Any help is appreciated; thanks in advance.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I would suggest checking if the material used by this font asset is the correct one after loading the bundle. If it is the correct material, check if the correct shader is also assigned to this material.

    It is possible that the reference to the shader is lost for some reason.

    P.S. If the material and shaders references appear to be correct and you are able to reliably reproduce this issue, please submit a bug report with repro project. Please provide the case # once you have it and I'll be more than happy to take a closer look.
     
  3. aaversa

    aaversa

    Joined:
    Sep 5, 2016
    Posts:
    41
    I've tried replicating this in a fresh project using the same bundle loading code and the same font assets; the bug did not occur there, but I noticed that in the fresh project, the material is defaulting to "LiberationSans SDF Material". I don't understand why this is the case. My code in my main project does not adjust font materials at all. The only thing happening in my font switching function is adjusting the .font property. So, I don't know how this behavior is happening or how to replicate it.

    Do you have any idea how or why the references to the shaders/materials would be broken when loading from the asset bundle? Of course, I have tried rebuilding the bundles from scratch many times. And clearly the shaders/material are 100% fine because if I load the fonts via Resources.Load or leave them in the scene, it works perfectly fine.

    EDIT: For total clarity, if I look at the AssetBundle-loaded fonts in the inspector, they do appear to have the correct materials. For example my TMP_FontAsset called "CT White", when inspected, has the auto-generated material "CT White Material".
     
    Last edited: Feb 7, 2022
  4. aaversa

    aaversa

    Joined:
    Sep 5, 2016
    Posts:
    41
    Oh my god OK I figured it out after banging my head against the wall for hours. The TMP shaders were not located in the bundle. Why or how this changed I have literally absolutely 0 idea, because I didn't change anything with our bundles or assets when changing editor versions. But that was it. Manually dragging the shaders in one by one.
     
    Stephan_B likes this.
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Glad you figured it out.