TMP event subscription only runs when enabling, how to make it run every time the event is called

Hello,

I am trying to find a way to automatically update the text of a TMP in several places upon modification in just one (for outlines, drop shadows & stuff alike).

I stumbled on the explanation using TMP example 23 with TMPro_EventManager.TEXT_CHANGED_EVENT and wrote as recommended:

    void OnEnable()
    {
        TMPro_EventManager.TEXT_CHANGED_EVENT.Add(OnTextChanged);
    }

    void OnDisable()
    {
        TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(OnTextChanged);
    }

    void OnTextChanged(Object objectChanged)
    {
        if (objectChanged == textToCopy)
        {
            // do something
            // ...
            Debug.Log("updating text");
        }
    }

Now, the script only works if I do disable and enable it again in the inspector.

I’m not sure of what I am doing wrong, in principle subscribing to an event is permanent once the script is enabled? In my mind, the script is telling that every time the event is called, OnTextChanged will be called, but what it is doing is that it is called only when the script is effectively enabled just as if I wrote the update in the OnEnable() itself.

Does anyone see what isn’t working here?

Thank you very much!

Okay, the problem wasn’t the event, it was that the text mesh wasn’t properly updating even though the text content was.

    void ON_TEXT_CHANGED(Object objectChanged)
    {
        if (objectChanged == textToCopy)
        {
            currentTMP.SetText(textToCopy.text);
            currentTMP.ForceMeshUpdate(true);
            Debug.Log("updating text");
        }
    }