Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Bug TMP TextInfo not updating instantly after changing TMP Text

Discussion in 'UGUI & TextMesh Pro' started by WolfVD, Aug 26, 2020.

  1. WolfVD


    Jul 11, 2020
    The title.

    I came across this bug with a code segment similar to the following where inputField is of type TMP_Text and otherString is a regular string (I didn't test out this particular piece of code, just used for demonstration purposes):
    Code (CSharp):
    1. inputField.text = inputField.text + otherString;
    3. Debug.Log(inputField.textInfo.characterInfo[inputField.text.Length-1].character);
    This piece of code will print out a blank line. To get the Debug.Log to work correctly, it must be in Update and will usually register the change to TMP_Text after one or two Update calls.

    An easy issue to work around, but annoying nonetheless.
  2. Stephan_B


    Unity Technologies

    Feb 26, 2017
    Whenever properties of the text object change, the text object will be processed / regenerated which happens late in the update cycle and just before the camera is rendered. When the text object is updated, the content of the textInfo will be updated to reflect these changes.

    For most use case, this is fine but in some cases where you need access to the text info right away, you can use ForceMeshUpdate() which has several overloads to force an update of the text object which will result in the textInfo being updated.