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?
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):
// ReSharper disable CheckNamespace
using TMPro;
using UnityEditor;
namespace EditorExt {
public class FontAssetUpdateWindow : EditorWindow {
#region [Fields]
private TMP_FontAsset _asset;
#endregion
[MenuItem("Tools/Font Asset Force Updater")]
private static void OpenWindow() {
FontAssetUpdateWindow window = CreateWindow<FontAssetUpdateWindow>("Font Asset Force Updater");
window.Show();
}
private void OnEnable() { EditorApplication.update += PerformUpdate; }
private void OnDisable() { EditorApplication.update -= PerformUpdate; }
private void PerformUpdate() {
if (_asset == null) return;
TMP_Text[] texts = FindObjectsOfType<TMP_Text>();
foreach (TMP_Text text in texts) {
if (text.font == _asset) {
text.havePropertiesChanged = true;
}
}
}
private void OnGUI() {
_asset = (TMP_FontAsset) EditorGUILayout.ObjectField(_asset, typeof(TMP_FontAsset), false);
}
}
}