Search Unity

TextMesh Pro [Resolved] Need to reduce runtime memory

Discussion in 'UGUI & TextMesh Pro' started by cquels, Jan 26, 2021.

  1. cquels

    cquels

    Joined:
    Sep 11, 2016
    Posts:
    10
    We need to reduce the amount of memory being used by our game at runtime. Do you have any suggestions on the TextMesh Pro front? We plan on using only static font assets (the user can't enter any text, so we don't need dynamic font assets) and currently have a large chain of fallbacks (English >> Arabic >> Korean >> Chinese >> etc.) defined on the English font asset (not in TMP Settings).

    I should mention that we are using the i2 localization asset. So we don't have all of those languages displayed in the game simultaneously; the text is swapped out by i2 according to the language that the player picks on the title screen.

    One thought is that, since a player picks a language on the title screen, maybe we'd save memory if we could somehow load only the chosen language and not all the others. (E.g., if the player picks Korean, isn't our fallback chain in fact wasting memory on the English, Arabic, and Chinese atlases?) Would that actually help us? If so, how do we set that up? And if the player later returns to the title screen and picks a different language (e.g., after playing for while in Korean they decide they'd rather play in English instead), how do we unload one language and load the other?

    A second thought is that maybe we've made a mistake in having a large fallback chain as I described. If so, what is the recommended method for a game with multiple languages?
     
    Last edited: Jan 26, 2021
  2. cquels

    cquels

    Joined:
    Sep 11, 2016
    Posts:
    10
    So we think we've solved it. What we basically did was:
    • Remove all fallbacks from our English font asset, which I'll call the parentFontAsset.
    • Know for each language the path to and names of the font assets that should/shouldn't be fallbacks.
    • Pass in the parentFontAsset as a TMP_FontAsset to our main function.
    • When the language is selected, iterate through the parentFontAsset.fallbackFontAssetTable. If you see something that shouldn't be a fallback (I know we removed them in the first step, but our code may add them back if language is switched), remove it by calling:
    Code (CSharp):
    1. Resources.UnloadAsset(parentFontAsset.fallbackFontAssetTable[i]);
    2. parentFontAsset.fallbackFontAssetTable.RemoveAt(i);
    • If there's anything that should be a fallback for the selected language and isn't already in the parentFontAsset.fallbackFontAssetTable, add it by calling:
    Code (CSharp):
    1. var newlyLoaded = Resources.Load<TMP_FontAsset>(pathToAndNameOfFallbackFontAsset);
    2. parentFontAsset.fallbackFontAssetTable.Add(newlyLoaded);
     
    Last edited: Jan 28, 2021
    starstablesimon likes this.