Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro [Feature request] Raise an event when changing the text in TextMeshProUGUI

Discussion in 'UGUI & TextMesh Pro' started by Grumpy-Dot, Sep 29, 2020.

  1. Grumpy-Dot

    Grumpy-Dot

    Joined:
    Feb 29, 2016
    Posts:
    93
    Would it be possible to get an event when the TextMeshProUGUI text has changed? I am aware this might add a small performance penalty, so perhaps also add a way to not raise it if not set.

    This will allow me to add custom text animations and other features and not care which component changed the text, either the localization plugin, or some other custom script.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    To modify the incoming text, you could consider creating a script implementing the ITextPreprocessor which was added recently.

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Interface used for preprocessing and shaping of text.
    4. /// </summary>
    5. public interface ITextPreprocessor
    6. {
    7.     /// <summary>
    8.     /// Function used for preprocessing of text
    9.     /// </summary>
    10.     /// <param name="text">Source text to be processed</param>
    11.     /// <returns>Processed text</returns>
    12.     string PreprocessText(string text);
    13. }
    14.  
    There should be a few posts about this on the forum.
     
    Grumpy-Dot and Peter77 like this.