Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug FontAssets created with TMP_FontAsset.CreateFontAsset do not render correctly on Android

Discussion in 'UGUI & TextMesh Pro' started by jason_wang_pianista, Apr 21, 2023.

  1. jason_wang_pianista

    jason_wang_pianista

    Joined:
    Oct 28, 2022
    Posts:
    5
    Unity Version : 2021.3.17f LTS

    When using CreateFontAssetFromFamily on Android, fonts are rendered with strange spaces.

    The device tested is the Galaxy Z Fold II and the screenshots are as follows.
    Screenshot_20230421_152312_Brick Shooter  World Tour.jpg
    Screenshot_20230421_152843_Brick Shooter  World Tour.jpg

    And this problem seems to happen when the text is long.
    Screenshot_20230421_152318_Brick Shooter  World Tour.jpg

    The specified Font Family is Roboto - Regular and the last shot shows the difference from the regular LiberationSans SDF.
    (The one labeled Test below is a LiberationSans SDF pre-built in the editor)
    Screenshot_20230421_154936_Brick Shooter  World Tour.jpg

    The code used is roughly this

    Code (CSharp):
    1. var asset = TMP_FontAsset.CreateFontAsset
    2. (
    3.     familyName: "Roboto",
    4.     styleName: "Regular",
    5.     pointSize: 90
    6. );
    For a CreateFontAsset function that specifies a Font Family, there are limited additional parameters that can be specified here.

    How can I solve this problem?


    Note 1. I have never encountered this issue in the Unity Editor (macOS, Windows) and the standalone player Windows.

    Note 2. I used the DeepL translator, so the context may be a bit awkward.

    Note 3. I am trying to use the CreateFontAsset function at runtime for text localization. The only Android phone I have is the Galaxy Z Fold 2, so I don't know the results on other Android phones yet.

    [Edited]
    Note 4. TMP version = 3.2.0-pre.4
     
    Last edited: Apr 21, 2023
  2. jason_wang_pianista

    jason_wang_pianista

    Joined:
    Oct 28, 2022
    Posts:
    5
    I left out some important information in the previous post.

    The fonts I created with CreateFontAsset are working with fallbackFontAssetTable.

    I first prepared NotoSans with the built-in dummy and set the Atlas Population Mode to Dynamic OS.
    noto3.png
    noto.png
    noto2.png

    Then I set up the following fallback to actually replace those fonts with the system fonts.

    Code (CSharp):
    1. var asset = TMP_FontAsset.CreateFontAsset
    2. (
    3.     familyName: "Roboto",
    4.     styleName: "Regular",
    5.     pointSize: 90
    6. );
    7.  
    8. if (null == builtInFont.fallbackFontAssetTable)
    9.     builtInFont.fallbackFontAssetTable = new List<TMP_FontAsset>();
    10.  
    11. builtInFont.fallbackFontAssetTable.Add(asset);
    This causes text rendering issues on Android (Galaxy Z Fold 2).
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,755
  4. jason_wang_pianista

    jason_wang_pianista

    Joined:
    Oct 28, 2022
    Posts:
    5
    Ten minutes ago I created a new sample project, successfully reproduced the issue and submitted a bug report.

    Now I'm waiting for a confirmation email.
    reported.png

    Also, I didn't specify the TMP version in the first post, it's 3.2.0-pre.4.
     
    karl_jones likes this.
  5. jason_wang_pianista

    jason_wang_pianista

    Joined:
    Oct 28, 2022
    Posts:
    5
    I'll share a sample here as well.

    How to reproduce the issue

    Step 1
    Download the sample project and open it with Unity 2021.3 LTS version

    Step 2
    Build the SampleScene on Android

    I expect the same issue to always occur when running the build on the Galaxy Z Fold 2.

    I'm also curious if this happens on other phones as well.
     

    Attached Files:

  6. jason_wang_pianista

    jason_wang_pianista

    Joined:
    Oct 28, 2022
    Posts:
    5
    [Updated]
    Noto Sans CJK KR did not have the problem.

    So far, we've found that this only happens on Android's "Roboto", so it seems to be a "specific font issue".

    So for now, I think I can specialize to not put certain fonts in the fallback.
    (It's a little scary not knowing everything about case-by-case if a particular font will cause problems on a particular device)

    And I was wondering if it is normal for this to happen when TMP encounters certain fonts.