<TEXTMESH PRO> Looping Through Vertex Colors on Different Text makes some characters tint darker

Hello,
I’m using the TMP_TextSelector_b code. I modified it to change text color when a link is clicked.

It applies the tint in an offset pattern - So some letters are tinted darker or left out.

Here’s a sample…
Engine Controls - <link=Key Switch>Key Switch, <link=Accelerator>Accelerator and <link=Engine Shutdown >Engine Shutdown

// Get a reference to the vertex color
Color32[ ] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
Color32 c = vertexColors[vertexIndex + 0].Tint(0.75f);
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;

I have more text to inject at run-time. Letters are tinted darker or left out.

Any ideas what’s wrong?

Not sure if anybody figured this out altready but i was faced with this issue myself and was finally able to find a solution, so basically the problem is that you are trying to change the color for all the vertex of an empty space (because most likelly than not your link is composed of 2 or more words), so what you have to do while iterating is check wether or not the current character is an empty space, and skip it if it is

//The for that loops through your link text
for (int i = 0; i < wInfo.linkTextLength; i++)
{

//get the current character
char currentCharacter = m_TextMeshPro.textInfo.characterInfo[characterIndex].character;

//Skip if it's an empty space
if (currentCharacter == ' ') continue;

//the rest of your color/tint chaning logic goes here

}
1 Like

Thanks so much for posting this. I struggled with this for many hours. I don’t think I ever would’ve figured it out if I hadn’t found this post.