TMP: textInfo.linkInfo does not update after changing text

Hi, I’m having an issue with the latest TextMeshPro version (3.0.4) in the latest Unity release (2020.2.7). When I create a TMP UI component containing some tags then change the text at runtime, the linkInfo array never updates.

Here is a simple demo project: http://thomascastiglione.com/TMP-linkinfo-bug-demo.zip

The project contains the following script, which replaces the initial two links with one link and then none:

using System.Collections;
using TMPro;
using UnityEngine;

public class LinkModifier : MonoBehaviour
{
    private TextMeshProUGUI textMeshPro;

    void Start()
    {
        textMeshPro = GetComponent<TextMeshProUGUI>();
        StartCoroutine(ModifyLinks());
    }

    void Update()
    {
        Debug.Log(textMeshPro.textInfo.linkInfo.Length);
    }

    IEnumerator ModifyLinks()
    {
        yield return new WaitForSeconds(2);

        textMeshPro.text = "<link>Sole Link</link>";

        yield return new WaitForSeconds(2);

        textMeshPro.text = "";
    }
}

Despite these modifications, the linkInfo doesn’t update, and Update() prints “2” every frame thereafter.

Also seeing this. Unity 2020.3.0f1, package version 3.0.6

I’ll try taking a closer look later today or over the next few days.

Please feel free to bump this thread if I fail to follow up by the end of the week.

@Stephan_B Did you get to the bottom of this, encountering this issue just a day before game jam deadline :frowning:

Finally had a chance to take a closer look at the above.

The reason why “textMeshPro.textInfo.linkInfo.Length” always returns the same value is because text processing buffers such as characterInfo, wordInfo, linkInfo, etc. are all allocated in blocks. This is an optimization to minimize how often we allocated these buffers.

As such, you cannot rely on the length of those arrays but instead must use the relevant textInfo property such as in this case “textMeshPro.textInfo.linkCount” or characterCount if you were to iterate over the characterInfo for instance.