Search Unity

TextMesh Pro Loading Atlas on demand

Discussion in 'UGUI & TextMesh Pro' started by ooochris, Nov 3, 2020.

  1. ooochris

    ooochris

    Joined:
    Jul 21, 2013
    Posts:
    5
    Hello,

    I'm wandering what's the best way to go about it?

    My use case are:
    1. the player plays in english but sees a japanese player in a leaderboard. I'd like to only load the japanese font in memory when we encounter those japanese characters. I tried to add the jp as fallback of the English font but then the atlas is loaded at startup in memory even if player never sees a jp character.

    2. if the player plays in English I do not want to load the japanese font in memory. Only when he switches to japanese, I'd like to load that font in memory. For that I'm currently adding the jp font as fallback by code with
    font.fallbackFontAssetTable.Add(fontAsset)


    Any ideas?
    Thanks for you help.
     
  2. ooochris

    ooochris

    Joined:
    Jul 21, 2013
    Posts:
    5
    No one has done something similar?
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I would suggest using a dynamic font asset to handle the Japanese / potentially CJK text.

    This dynamic font asset should be reset prior to creating a build / have the new "Clear Dynamic Data On Build" enabled as seen below.

    upload_2020-11-10_13-3-9.png

    Resetting the font asset prior to the build clears all font data including setting the atlas texture size to zero. As such, even though the atlas will be loaded since it is referenced by the primary font asset or in the TMP Settings, its atlas will only be resized to the size defined in the General Setting when the first glyph is added to the atlas texture.

    Note: Changes to dynamic font assets in the Editor are persistent but not at runtime. As such, dynamic font asset will always revert back to their build state between play sessions.

    I would recommend enabling Multi Atlas Texture which will allow this dynamic font asset to create / add new atlas textures as needed in the event the first atlas is full. This makes it possible for this font asset to handle every possible character / glyph contained in the source font file.
     

    Attached Files:

  4. ooochris

    ooochris

    Joined:
    Jul 21, 2013
    Posts:
    5
    I'll try that. Thanks