- Home /
Programatically changing Text Mesh Pro font
Hello everyone. I'm introducing localization into my game, and I;m running into trouble when I try to programatically change the font of a Text Mesh Pro asset when a button is pressed. This is the script:`
public TMP_FontAsset normalFontTMP, russianFontTMP;
public void localize () {
textMeshPro.text = LocalizationText.GetText(key);
if (LocalizationText.GetLanguage().Equals("RU"))
{
Debug.Log("Russian");
textMeshPro.font = russianFontTMP;
textMeshPro.fontSharedMaterial = russianFontTMP.material;
}
else
{
Debug.Log("NOrmal");
textMeshPro.font = normalFontTMP;
textMeshPro.fontSharedMaterial = normalFontTMP.material;
}
}`
The font or text doesn't update until the Text Mesh Pro's object is disabled and re-enabled. I'm not entirely sure if I'm doing this correctly. Could someone pleas offer some assistance?
I far did you get with this, I am dealing with some localization issues myself, and was wondering how your project turned out?
@bgprocks I solved the problem - I wasn't meant to be messing with fontShared$$anonymous$$aterial, and there were a few missing references in my buttons. I used this asset
Answer by noeloskar99 · May 29, 2021 at 09:56 PM
add textMeshPro.UpdateFontAsset(); it's 3 years old so you probably don't care, but someone else may find it usefull
Your answer
Follow this Question
Related Questions
Convert TextMesh Pro to Custom Font 0 Answers
Custom Font works in editor but not in build 2 Answers
How to change text on a TextMesh with a non-dynamic font on iOS? 2 Answers
TextMeshProUGUI Font Disappearing on Low FPS,Unity TextMeshProUGUI Font Disappearing 0 Answers
How to fix TextMeshPro breaking lines and escaping random characters? 0 Answers