Search Unity

TextMesh Pro Multiple dynamic font fallbacks

Discussion in 'UGUI & TextMesh Pro' started by mvaz_p, Sep 2, 2019.

  1. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Hi, I'm trying to setup TMP for CJK support and noticed a strange behaviour when multiple dynamic font assets are included in the fallback list.

    For example, I have a main Latin font with the following fallbacks:
    Latin Dynamic
    Japanese with Japanese Dynamic as fallback

    The problem is that Japanese Dynamic is never reached, all missing characters seems to be caught by Latin Dynamic, but the font doesn't always have those characters and so they are rendered as whitespaces.

    Is this the expected behaviour or am I doing something wrong?

    Also, it's necessary to use the dynamic generation because there are some sections in the game that might contain text from unknown sources.
    Thanks.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Search for the requested character through the various Font Assets and Fallbacks is as follows:
    • Search the Primary font asset and return character if found
    • Check if any fallbacks are assigned to the Primary font asset
      • Search through the fallback list starting with first on the list and recursively through any of its own fallbacks and return the character if found. Otherwise search next fallback on list.
    • Check if any sprite asset are assigned to the text object as it may contain sprite assigned a unicode value. Sprite assets can also have fallback of their own.
    • Check if TMP Settings contains a list of Fallbacks and if so search through those in the same many as local fallbacks assigned to the primary.
    • Check if Default Sprite Asset assigned in TMP Setting contains a sprite with the given Unicode. Search potential fallback of default sprite asset as well.
    • Search Default Font Asset assigned in TMP Settings. Check if it has a list of Fallbacks as well.
    • Lastly, display missing glyph character defined in TMP Settings.
    Static font assets will only be searched to see if they already contain the requested character. Dynamic font assets are queried for the missing character and then the font loaded to check if it may contain the requested character and if so, it will be added to the dynamic font asset.

    Now to your specific report. If the Latin font asset contains the requested Japanese characters or if this font asset is Dynamic and its font contains those Japanese characters, TMP will add those to the Latin font asset.

    If you do not want characters to be added to a Dynamic font asset, you have to set it to Static mode. There is no language filtering on font assets. Ie. If set to dynamic and the character exists in the font file, it will be added (provided there is room in the Atlas texture of course).

    The recommended workflow is to have all known text / characters be included in static font assets for best performance / quality assurance and then rely on the dynamic system to handle unknown characters which may come from user input or other sources. So yes, you have to use dynamic font assets / fallbacks for those.
     
    mvaz_p likes this.
  3. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Hi, Stephan. Thanks for the in depth answer.

    The issue is that neither the Latin font asset nor the font contains Japanese characters (it's Noto Sans), but the fallbacks are still not reaching the Japanese Dynamic font asset for generating the missing characters. And those characters exist on the Japanese font.

    I'm on Unity 2019.1.14f1 and TextMeshPro 2.0.1.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you post a few images showing the Inspector of (1) the Primary font asset which I assume is NotoSans. (2) Each of the fallback font assets assigned to the Primary.

    Make sure I can see the Generation Settings and Fallback List of each of those font assets.

    I just want to make sure I understand the setup / structure of these font assets / fallbacks.
     
    mvaz_p likes this.
  5. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Oh well, just tried to reproduce it clearly and print it for you but it didn't happen.
    Everything worked just fine. Something must have been badly configured before.
    Sorry for taking your time.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Glad it is now working correctly :)
     
  7. mvaz_p

    mvaz_p

    Joined:
    Aug 22, 2018
    Posts:
    80
    Just a quick update if it helps someone.
    It seems this issue was happening because I created the dynamic fallback font assets by duplicating the original font asset, The issue went away as soon as I generated a new atlas for the dynamic font asset.