Skip to content

Instantly share code, notes, and snippets.

Last active December 18, 2022 16:21
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Localize the default TextMeshPro font.
using System.Reflection;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
/// <summary>
/// Sets the default TextMeshPro font to be used.
/// </summary>
public class DefaultTmpFont : MonoBehaviour
public LocalizedTmpFont localizedFont = new LocalizedTmpFont();
public bool updateExistingText = true;
void OnEnable() => localizedFont.AssetChanged += LocalizedFont_AssetChanged;
void OnDisable() => localizedFont.AssetChanged -= LocalizedFont_AssetChanged;
void LocalizedFont_AssetChanged(TMP_FontAsset value)
// Requires TMP 3.2 or greater
TMP_Settings.defaultFontAsset = value;
// Do we want to update any text that is already displayed with the new font?
if (updateExistingText)
var o = FindObjectsOfType<TextMeshProUGUI>();
foreach (var p in o)
p.font = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment