Search Unity

TextMesh Pro Change Font for all TextMeshProUGUI at runtime

Discussion in 'UGUI & TextMesh Pro' started by tng2903, Nov 17, 2019.

  1. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    41
    Is there any way to change the font for all TextMeshProUGUI at runtime? For example, when user change the language of the game, it will load up the best AtlasFontAsset for that language and use that to display the text.

    Manually GetComponents<> and change them in OnEnable seems a little tedious to me :D, is there a hidden way of this feature already integrated in TextMeshPro?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    There are different ways to handle this. Many users use AssetStore tools like I2 Localization to manage language specific resources such as changing the text, font asset and other settings based on language selection.

    Other users have implemented their own managers that keep track of text objects and handle changing relevant settings when a new language selection is made. All these custom implementation end up using some list or dictionary to track text objects in a project / scene / etc.
     
  3. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    41
    Thank you for your pointer, it currently what I've been using to change the font (somewhat more naive, tho, that is, use GetComponents and change the font in OnFontChangedEvent). But it would be a big help if we can have a sort of virtual wrapper font sit in-between the actual FontAsset and the TextMeshPro components. So if we want to change the font for all NORMAL text, we could just grab the NORMAL wrapper font, and change it to another FontAsset, then all the TMP components that use that wrapper font will have new FontAsset assigned. Is there any chance that this feature has already included in TextMeshPro?
     
  4. CChong_at_Infinity

    CChong_at_Infinity

    Joined:
    Apr 7, 2020
    Posts:
    27
    Sorry to necro an old thread, but did you ever find a solution to this?

    I'm in a situation where I might have to swap out fonts instead of relying on the Font Asset Fallback feature, due to various circumstances.
     
  5. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    41
    as a Unity user, you should know that there are things you just have to do it yourself, or go to AssetStore.
    I hacked a 'solution' for that project's requirement, and i'm afraid you will have to do it too since i don't remember where it went :D.
    the gist of it is to browse through the scenes, find TMP component and change the font one by one.