Search Unity

Can I change TextMeshPro Dynamic Font Atlas Size in Runtime?

Discussion in 'UGUI & TextMesh Pro' started by yuewahchan, May 8, 2019.

  1. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
    For CJK font asset, it set atlas size is set to 2K, however it occupy to much space in the build. So, can I set it to smallest and increase the size in runtime ?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,205
    The size of the atlas is determined when you create the font asset.

    By default it is 1024 x 1024 which can be changed in the Editor via the Generation Settings or when creating a font asset at runtime via

    Code (csharp):
    1. public static TMP_FontAsset CreateFontAsset(Font font, int samplingPointSize, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode = AtlasPopulationMode.Dynamic)
    When font assets are created or reset (via the context menu), the atlas is set to a size of zero and only resized to their defined size when the first character is added. As such when including dynamic font assets / fallbacks, they will not materially increase the build size since their texture is zero x zero. (Assuming you Reset them before building).

    Currently font asset only have a single atlas texture, in the future release of TMP (version 1.4.2 for Unity 2018.3 and 2.0.2 for Unity 2019.1) Multi Atlas Texture support will be added allowing font assets to have multi atlas textures which are created as needed.
     
  3. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    When I use dynamic sdf , How can I detect character is over altas size?
    Have any event ? or somthing? or use "TMP_FontAssetUtilities.GetCharacterFromFontAsset" this api to check ?
    because if atlas is full , I want to create a new dynaimic Font asset at runtime to handle that .
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,205
    In the latest release of the TMP package, a new feature was added called Multi Atlas Texture which will automatically add new atlas textures to handle glyphs that do not fit in the current atlas.

    This feature is enabled per font asset in the Generation Settings.

    upload_2020-8-10_11-49-54.png

    The latest release of the TMP package is version 1.5.1 for Unity 2018.4, version 2.1.1 for Unity 2019.4 and version 3.0.1 for Unity 2020.x.
     
  5. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    Thanks your answer . But when I update to 1.5.1 I got this compile error meesage :

    Library\PackageCache\com.unity.textmeshpro@1.5.1\Scripts\Editor\TMPro_FontAssetCreatorWindow.cs(11,19): error CS0234: The type or namespace name 'TextCore' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)

    I'm using unity 2018.4.2f1 , How can I fix that?

    I using 1.4.1 version it work fine. but I can't update to 1.5.1 version
     
  6. tim12332000

    tim12332000

    Joined:
    Jun 15, 2017
    Posts:
    20
    By the way , I can use 1.5.0 with 2018.4.2f1 , It's also have "Multi Atlas Texture"
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,205
    The above error seems strange and might be related to some Library cache issue.

    It might be related to the fact you are using an early version of 2018.4. I would suggest updating to one of the newer release of 2018.4 although it is strange 1.5.0 would be fine.

    Let me know if the above helps?
     
  8. Shane_Watson_87

    Shane_Watson_87

    Joined:
    Jul 15, 2013
    Posts:
    1
    How to change fonts through Asset Bundle when I am using Textmesh Pro.

    In the project, I will changes fonts asset successfully but when i m try to set font through Asset Bundle at that time not set asset bundle font successfully
     
unityunity