Search Unity

TextMesh Pro Changing font asset glyphs / properties fails to update TMP_Texts in scene / game

Discussion in 'UGUI & TextMesh Pro' started by xVergilx, Mar 16, 2021.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    For some reason it stopped working in Unity 2020.2.7f1 & TMP 3.0.4;

    Changing value in font asset (e.g. baseline), only changes it once, then it stops completely until next playmode enter / exit.

    This is quite unfortunate, because there's no other way to tweak font properties.
    Is there any workaround?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Upon further look, it seems like TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, fontAsset) fails to notify TMP_Text objects correctly;

    Setting manually hasPropertyChanged does the trick, although its suboptimal;

    As a temporary workaround, I've made this hack (a bit GC heavy, so don't forget to close the window after you're done tweaking):
    Code (CSharp):
    1. // ReSharper disable CheckNamespace
    2.  
    3. using TMPro;
    4. using UnityEditor;
    5.  
    6. namespace EditorExt {
    7.    public class FontAssetUpdateWindow : EditorWindow {
    8.       #region [Fields]
    9.  
    10.       private TMP_FontAsset _asset;
    11.  
    12.       #endregion
    13.  
    14.       [MenuItem("Tools/Font Asset Force Updater")]
    15.       private static void OpenWindow() {
    16.          FontAssetUpdateWindow window = CreateWindow<FontAssetUpdateWindow>("Font Asset Force Updater");
    17.          window.Show();
    18.       }
    19.  
    20.       private void OnEnable() { EditorApplication.update += PerformUpdate; }
    21.  
    22.       private void OnDisable() { EditorApplication.update -= PerformUpdate; }
    23.  
    24.       private void PerformUpdate() {
    25.          if (_asset == null) return;
    26.        
    27.          TMP_Text[] texts = FindObjectsOfType<TMP_Text>();
    28.          foreach (TMP_Text text in texts) {
    29.             if (text.font == _asset) {
    30.                text.havePropertiesChanged = true;
    31.             }
    32.          }
    33.       }
    34.  
    35.       private void OnGUI() {
    36.          _asset = (TMP_FontAsset) EditorGUILayout.ObjectField(_asset, typeof(TMP_FontAsset), false);
    37.       }
    38.    }
    39. }