Search Unity

Asset file bloats up [NotoSansCJK]

Discussion in 'UGUI & TextMesh Pro' started by OlafsOsh, Oct 22, 2020.

  1. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Good day!

    Since I have Japanese localization, I imported the NotoSansCJK-Regular into a build. Unfortunately I got struck bu an error from Github, as the font asset file is 140MB big. Which is massive. It bloated to these proportions although font's original size is 16MB.

    Any way to remedy the situation? Otherwise I cannot Push it to repository. :/
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you post an image of the Font Asset Generation Settings?
     
  3. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    You bet!

    upload_2020-10-22_23-43-40.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since the Atlas size is 8192 x 8192, the texture alone is 64MB.

    My recommendation is that instead of using a huge 8192 x 8192 Atlas texture, to create a static font asset that only contains the known characters / text used in the project. Most likely you should be able to fit all those characters in a 1024 x 1024 and potential be able to increase the sampling point size.

    Then to handle all potential characters coming from user input or other sources (not known at build time), create a Dynamic font asset with Multi Atlas Texture enabled and assign it as fallback to your primary static font asset.

    This atlas can also be 1024 x 1024. Make sure you use the same Sampling Point Size to Padding Ratio as the Primary static font asset to ensure the visual appearance of Outlines, Shadows, etc. are consistent between the Primary and fallback. Just to be clear the Ratio of sampling point size to padding has to be the same but not the sampling and padding. For instance, the Primary could use sampling point size of 90 with padding of 9 for a 10% ratio. The dynamic fallback could have a sampling point size of 60 with padding of 6 for the same ratio of 10%.

    When Dynamic font assets are created or reset via the context menu, their atlas texture size is zero. Then when the first glyph is added, their atlas texture is resized to the defined size in the Generation Settings. As such and provided you reset them before creating your build, their contribution to build size is marginal.

    Changes to Dynamic font assets in the Editor are persistent which is why you should reset them before a build unless you want to ship them partially filled. At runtime and at the start of each play session, they always revert back to their shipping state which is they were reset is back to empty / zero size.

    Multi Atlas Texture makes it possible for the dynamic font asset to add new atlas textures as needed in the event the first atlas texture is full. This makes it possible for a dynamic font asset with multi atlas texture to potentially handle every single glyph contained in a font file.

    Using the above recommendation will result in your primary static font asset taking slightly more than 1 MB. The dynamic font asset assigned as fallback to your primary static should take a few kilobytes provided you reset it before the build. Then since the dynamic font asset references the font file, it will be included in the build and thus contribute whatever its size is. So in your case, I would expect this revised setup to be about 16MB + 1MB + kilobytes. So less than 18MB vs. 140MB.

    See the following videos which cover all of this and how to handle CJK.



     
  5. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Woah! Thank you!

    This is my Fallback font from the getgo. Are you saying, that I can just resize the atlas to, say 1024x1024, make a padding somewhat 40/4 and I will be good to go?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Pretty much.

    Make sure you enable Multi Atlas Texture on the Fallback. Also be sure to Reset it before creating your build to make sure the Fallback is empty with its atlas texture back to size = 0.

    P.S. In the next release of TMP, you will be able to set "Clear Dynamic Data on Build" per font asset. This will automatically Reset those font asset when you create a build. This way you don't have to remember to do it manually.
     
  7. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Amazing.I cannot find where to enable it, though:/

    upload_2020-10-24_0-33-15.png


    Those are setting for TMP, and this is the font itself...

    upload_2020-10-24_0-35-34.png

    Am I missing something?
     

    Attached Files:

  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Enable Multi Atlas Textures?

    upload_2020-10-23_15-32-49.png

    Make sure you adjust / reduce the atlas texture width and height to something like 1024 x 1024.
     
    OlafsOsh likes this.
  9. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Thank you so much, man! Forgot my eyes somewhere :)
     
  10. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Hey, @Stephan_B ! Unfortunately, upon importing in the new one, I get these errors:

    upload_2020-10-30_14-50-43.png

    I have everything as it was, but now it just does not work. Also layout of things goes bonkers.
     
  11. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    UPD. Made the atlas 4000x2000 - works now :/ At least in MainMenu :)
     
  12. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What do you mean by importing the new one? Where is this new one created and how is it imported?

    I would try to always use textures that are of the same width and height.

    I would not recommend using atlas textures larger than 2048 x 2048. If using dynamic font assets, I would use 1024 x 1024 with multi atlas texture enabled.
     
  13. OlafsOsh

    OlafsOsh

    Joined:
    Jul 10, 2018
    Posts:
    61
    Yes, I had exactly that.

    About "new one" - I regenerated the same font with different settings and overwrote existing one upon saving.