Search Unity

TextMesh Pro The addition of a OnTextChanged.

Discussion in 'UGUI & TextMesh Pro' started by triangle_klaas, Feb 26, 2020.

  1. triangle_klaas

    triangle_klaas

    Joined:
    Jul 30, 2019
    Posts:
    2
    Is there a way to subscribe to text changes of the standard TextMeshProUGUI?

    I am working on a script that automatically updates other texts to the value of a TextMeshProUGUI, to use for outlines or double texts and the such.

    Greetings, Klaas
     
    AldeRoberge likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Take a look at example 23 - Animating Vertex Attributes and related script which makes use of
    ON_TEXT_CHANGED event.

    These examples are included in the TMP Examples & Extras.
     
    triangle_klaas likes this.
  3. triangle_klaas

    triangle_klaas

    Joined:
    Jul 30, 2019
    Posts:
    2
    Ah, I missed that in the examples, thanks for the quick response.
     
  4. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    60
    Great. Now show me the code.

    Code (CSharp):
    1.        
    2.         TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
    3.  
    4.         void ON_TEXT_CHANGED(Object obj)
    5.         {
    6.             if (obj == m_TextComponent)
    7.                 hasTextChanged = true;
    8.         }
    Sorry for the necrobump, but I really wanted to not have to download the examples ;)
     
    Last edited: Mar 31, 2023