Search Unity

Question Can't use fallback fonts when using Addressables

Discussion in 'UGUI & TextMesh Pro' started by ysalpha, Oct 12, 2021.

  1. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    When I load a FontAsset set in Addressables at runtime and register a fallback, it does not work correctly.
    When the 'Play Mode Script' in Addressables is set to 'Use Asset Database', it is displayed correctly.
    However, when it is set to 'Use Existing Build', it is not displayed correctly.

    Specifically, the process is as follows.
    1. Create a Base SDF (alphanumeric static font) as a fallback source and register it in Addressables.
    2. Create JP Static SDF (static Japanese fonts) and JP Dynamic SDF (dynamic Japanese fonts) for fallback font, and register them in Addressables.
    3. Change the Play Mode Script in Addressables to 'Use Existing Build' and run 'Build -> New Build -> Default Build Script'.
    4. Attach the Base SDF to the Default Font Asset in TMP Settings, and create a TMP_Text on the scene.
      (it will leave the fallback list empty here.)
    5. Load Base SDF, JP Static SDF, and JP Dynamic SDF at the start of the scene, and register JP Static SDF and JP Dynamic SDF into the fallback list of Base SDF.
      baseSDF.fallbackFontAssetTable.Add( staticSDF );
      baseSDF.fallbackFontAssetTable.Add( dynamicSDF );
    6. After setting the fallback, set alphanumeric and Japanese text for TMP_Text.
    7. All Japanese characters except alphanumeric characters are not displayed and the following warning is displayed
      "The character with Unicode value \u3042 was not found in the [Base SDF] font asset or any potential fallbacks.It was replaced by Unicode character \u25A1 in text object [Text (TMP)]."

    I don't think it's a bug, but rather a problem with the references(depencencies) in the asset bundle.
    I can't think of a solution, but I'm having a hard time. Please Help...
    Attached is a sample project that shows this problem.

    OS:Windows 10
    Unity: 2020.3.18f1
    TextMeshPro:3.0.6
    Addressables:1.18.16
     

    Attached Files:

  2. ysalpha

    ysalpha

    Joined:
    Feb 2, 2017
    Posts:
    52
    I'm sure the following questions will arise, so I'll write down my thoughts in advance.

    Q. Why do you need to make font assets Addressables?
    A. If the UI prefab is set to Addressables and contains TMP_Text with Base SDF assigned,
     the Base SDF.asset will be contained in each UI prefab, so it needs to be taken out of Resources.

    Q. Why not register a fallback to Base SDF on Inspector beforehand?
    A. The specification of dynamically switching languages in the game is realized by switching the fallback font.
     Therefore, it is necessary to set the fallback on the runtime for Base SDF.

    Q. How about immediately after loading a prefab or scene, reattaching the dynamically loaded BaseSDF to all those TMP_FontAssets of TMP_Text?
    A. Possibly it can be done that way, but I'm not sure that's the smartest way to go about it.
     If possible, I would like to make this method a last resort.
     
  3. JTAU

    JTAU

    Joined:
    May 12, 2019
    Posts:
    24
    Was this ever solved?