Setting TextMeshProUGUI.text in edit mode

I have seen countless threads about text not updating but wasn’t able to find anything too useful.

I’m writing a component that manages a TextMeshProUGUI. My component has a text field which sets TextMeshProUGUI’s text property. As I type into my text field in edit mode, I can see in TextMeshProUGUI’s inspector that the text field does change, however the text itself as seen in the scene view or game view doesn’t change - until I make some other change like move the text, disabling and enabling it, or just deselecting the gameobject and reselecting it.

If I play the game, everything works fine and the text will update as soon as I set the text property.

I have tried all sorts of extra method calls like:

  • TextMeshPro.SetAllDirty();
  • TextMeshPro.ForceMeshUpdate();
  • Canvas.ForceUpdateCanvases();
  • LayoutRebuilder.MarkLayoutForRebuild(GetComponent());

Nothing works! Except if I do this:

TextMeshPro.enabled = false;
TextMeshPro.text = value;
TextMeshPro.enabled = true;

Which makes for a very slow editor when typing text

We are using version 2.1.1 in Unity 2019.4.1
Any suggestions? Thanks

I figured it out, turns out it’s not exactly TextMeshPro related, but more just how Unity’s editor works I guess? I had to call…

EditorApplication.QueuePlayerLoopUpdate();

… in my Editor script to make the text really update in edit mode. My guess is the way TextMeshPro works is properties and variables change in 1 frame, and then the real changes happens in the next frame. But outside of Play mode, frames don’t update consistently, so the change never really happens until I force a Player Update

4 Likes