TMP Problem: when you move, the text is updated

I use color changes of specific characters as in this lesson

but I also use my own font that creates SubMeshUI and I think that when I change Transform it is updated and repainted with the original color. With fonts that do not use SubMesh there is no such problem.

Video demonstration of the problem

Maybe there’s some way you can give up SubMesh, but I don’t know what he’s responsible for.

I realized it was because of the large number of characters in the font, but is there any way to change it? To make sure that SubMesh doesn’t update when it moves?

When changing colors, are you checking the MaterialIndex of each character to determine in which MeshInfo they are contained?

Take a look at the VertexJitter.cs script which does that.

I use a similar code on VertexJitter.

My Code

public void ChangeColorChars (int pageID, int stepID, Color32 color)
{
    for (int i = spritzScript.Pages[pageID].Steps[stepID].First; i <= spritzScript.Pages[pageID].Steps[stepID].Last; ++i)
        {
            if(m_TextMeshPro.textInfo.characterInfo[i].character != ' ' || m_TextMeshPro.textInfo.characterInfo[i].character != '\t' || m_TextMeshPro.textInfo.characterInfo[i].character != '    ')
            {
                int meshIndex = m_TextMeshPro.textInfo.characterInfo[i].materialReferenceIndex;
                int vertexIndex = m_TextMeshPro.textInfo.characterInfo[i].vertexIndex;
          
                Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
                vertexColors[vertexIndex + 0] = color;
                vertexColors[vertexIndex + 1] = color;
                vertexColors[vertexIndex + 2] = color;
                vertexColors[vertexIndex + 3] = color;
            }
          
        }

        m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
    }

But I decided to check if Jitter would work when moving if I had SubMesh present and it was not working when moving.

I temporarily fixed it by reducing the number of characters in the font.

Okay, I don’t know what the connection between my generated font and the original LiberationSans font was, but after LiberationSans was removed, SubMesh stopped showing up and the problem disappeared.

Sub mesh objects are used whenever a fallback font asset or sprite asset is used.

For instance, if you primary font asset is missing some characters, TMP would search any potential local and global fallbacks for the requested character and if found in one of the fallbacks, then a sub mesh would be created for this character.

You moving code probably doesn’t handle this correctly.

I do have my own ScrollView system, but even if I use the original UnityUI ScrollView and Text has SubMesh, JitterText does not work. Apparently, the transformation updates the mesh and recreates SubMesh again. As for me, the easiest solution would be to be able to turn off the search for missing characters.

What version of the TMP package are you using?

In the latest Preview releases of TMP, I added special handling to get around potential rounding errors in the calculation of the RectTransform size when using Stretch Anchoring modes where although the size of the RectTransform doesn’t change, the OnRectTransformDimensionsChange is called due to rounding errors.

I suspect, the vertex jitter might be trigger as a result of this.

I’ll use the last 14 preview version 2.1.0.