Search Unity

TextMesh Pro Font Atlas takes up too much memory.

Discussion in 'UGUI & TextMesh Pro' started by LeopardLiang, Aug 2, 2019.

  1. LeopardLiang

    LeopardLiang

    Joined:
    Feb 14, 2019
    Posts:
    9
    As shown below
    upload_2019-8-2_15-33-51.png

    upload_2019-8-2_15-32-57.png

    The memory displayed in the profiler does not match the one displayed in the Inspector.
    Any Help?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Dynamic Font Assets require setting the Texture flag to make it readable which typically results in 2X the memory footprint.

    Static Font Assets has this isReadble flag set to false and as such those textures take less memory.

    See the following about this flag.
     
  3. LeopardLiang

    LeopardLiang

    Joined:
    Feb 14, 2019
    Posts:
    9
    Thanks for the reply.
    But..Unfortunately....it is static Font Assets, even if I turn it off Is Readable, it also takes up twice as much memory
    upload_2019-8-2_16-5-41.png

    upload_2019-8-2_16-8-57.png

    upload_2019-8-2_16-9-20.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Was the IsReadable flag always set to false or did you change it and then didn't notice any difference?
     
  5. LeopardLiang

    LeopardLiang

    Joined:
    Feb 14, 2019
    Posts:
    9
    It is true when I just created the font.
    I changed it to false and nothing changed.
     
  6. LeopardLiang

    LeopardLiang

    Joined:
    Feb 14, 2019
    Posts:
    9
    Maybe I should build a debug package to test?
    Sometimes the Profiler of Editor is not so accurate.
     
  7. LeopardLiang

    LeopardLiang

    Joined:
    Feb 14, 2019
    Posts:
    9
    Hey Stephen!
    I built a development apk to test and found that it doesn't take up twice as much memory.
    Sure enough, the Profiler of Editor is not trusted.
     
    Stephan_B likes this.
  8. AdminBag

    AdminBag

    Joined:
    Sep 19, 2016
    Posts:
    18
    We have the same problem, is there a way to decrease font memory size?
    In the editor the font size is set to 2048x2048 4.0M but in the app we have 8k resolution for 8.0M.
    Screenshot 2021-09-13 at 10.47.25.png

    At the moment the fonts take up 107,5M because the game loads in memory all the atlas for all the languages.
    Do you have any advice?
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Dynamic font assets have 2x memory overhead due to Read / Write being enabled which is requires to add new glyphs in their atlas texture at runtime.

    Static font assets are 1x memory overhead since Write is disabled on them. As such, it is advisable to use static for the known text / characters used in the project and only use dynamic font assets for the unknown text / user input.

    For dynamic font assets, I also recommend using smaller atlas texture size like 1024 x 1024 or 512 x 512 with Multi Atlas Texture enable along with Clear Dynamic Data on build. This results in those atlas textures being size zero in builds thus reducing the app delivery size. Furthermore since these atlas textures are smaller to being with they have smaller memory footprint but still can grow to accommodate as many glyphs as needs with the Multi Atlas Texture that will create additional atlas texture as needed.

    Note: When a dynamic font asset is created, its atlas texture size will be zero. When the first glyph is added, the texture will be resized to whatever size was specified in the Creation Settings. If this size was 2048 x 2048, it would likely take a long time to fill this texture up with lots of glyph thus resulting in the a lot of wasted texture space and unnecessary memory overhead whereas if you started with a 512 x 512, it would take less memory but if it did end up being full, an additional 512 x 512 would be created to handle the additional glyphs. The trade off for multi atlas texture is (1) additional draw call per additional atlas texture. Draw calls mattered a lot back in the days of the iPhone 3s but that is no longer really the case as on most mobile devices now, there is no release performance difference between 1, 5, 25 or even 50 to 100 draw calls. You still want to be efficient with draw calls but having an extra potential draw calls due to multi atlas texture is much better than the much higher memory overhead (in my opinion).

    From a GPU point of view, it is also more efficient to read into smaller textures than larger textures where the sweet spot is around 1024 x 1024.
     
    Rafael_CS likes this.