Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Callback for text mesh changed? Trying to sync 2 TextmeshPros...

Discussion in 'UGUI & TextMesh Pro' started by petey, Sep 9, 2020.

  1. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Hi there!

    I have a bunch of scenes where I need to have multiple text mesh pro components display the same text. At the moment I have just split them out and I’m manually setting the text for each one in code. Just wondering, is there a way to automate that?
    I thought there might be a callback or something I could use but I’m not too sure.

    Any ideas would be great!
    Thanks,
    Pete
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The following event is available and used in a few of the TMP examples scenes like 23 - Animating Vertex Attributes which uses the VertexJitter.cs script which makes us of this event.

    Code (csharp):
    1.  
    2. // Subscribe to event fired when text object has been regenerated.
    3. TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
    4.  
    The following event was also added in the latest release to provide for an opportunity to modify the geometry of the text before it is uploaded to the mesh and renderer.

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Event to allow users to modify the content of the text info before the text is rendered.
    4. /// </summary>
    5. public override event Action<TMP_TextInfo> OnPreRenderText;
    6.  
    The first event will be more suitable to your use but just wanted to share information about the 2nd one as well.
     
    Last edited: Sep 9, 2020
  3. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,823
    Oh awesome! Thanks @Stephan_B! You’re the best!