Get single letter color?

So, I’m doing a dialog system for my game and, while adding some effects to the text, I’ve found myself in a situation where I need to get the color of a single letter inside the TextMeshPro Text.
What I mean by that is that I need to get the actual color of the letter, not the color of the text.

For example, if I use the tag <color=“red”> tag to make my BLACK text red, what I want to get is the red color, not the black color (which is the main color set in the inspector).

So… How would I do that?

Whenever a text object is rendered / processed, the TMP_Text.textInfo class is populated with information about every character, word, line, links, etc. including the underlying geometry of the text object.

By querying this TMP_Text.textInfo and the underlying structures like characterInfo[index] you can find out information about any given character including its color.

Several of the examples and related scripts included with TMP that makes use of this textInfo information. Take a look at example 12 - Link Example as well as 22 - Animating Vertex Attributes and the script they use which make use of this TMP_Text.textInfo.

There is also a script called TMP_TextInfoDebugTool.cs (also included in the TMP Examples & Extras) that you can add to any text object which will enable you to visualize the content of this textInfo. Take a look at the script to learn how it accesses and uses this information.