How to set rich text through script?

Hello everyone,
I am trying to set the rich text of my TextMeshProUGUI component through script, but I can’t.
I ran the following code,

myText.text = "< color =#E0E300>This is golden!</color>";

but the text that showed up was just “< color =#E0E300>This is golden!”, it didn’t parse the rich text tag, I wanted the text “This is golden!” to be yellow.

How can we set the rich text through script?

You have extra spaces in the rich text tag.

myText.text = "<color=#E0E300>This is golden!</color>";

Whenever you see the tag instead of its effect, this means the tag is invalid / incorrectly formatted.

2 Likes

Yes, that’s the issue! Many thanks.