# Display Rich Text in a TextMeshProUGUI component

I am rading a text to be displayed in a Text UI from an asset using the standard commands

Resources.Load<TextAsset>("nameOfMyTextAsset");


The text is a .txt.

The text contains richtext tags to format the text in bold or italics. The richtext tags are displayed as such.

I am using TextMesh Pro and insert the text via the following cmd

public TextAsset MainText;
this.GetComponentInChildren<TextMeshProUGUI>().text = MainText.text;


The text is displayed like this

How can I read text with richtext tags from a text asset?

• If you replace that last line with GetComponentInChildren<TextMeshProUGUI>().text = "<b>test string</b>" do you still see the tags? If not, then it's likely the brackets are getting escaped somehow. Walking through the string you get from MainText.text character-by-character, and reporting any character codes that shouldn't be there will help diagnose the issue. Aug 5 '16 at 12:26
• Excellent thought. I still do see the tags if I hardcode them though.
– JBJ
Aug 5 '16 at 12:42
• Then that means it's not the TextAsset source that's to blame. The TextMeshProUGUI component seems to not be using the tags it's given via the text property. Does the component expose a flag to enable rich text, or a SetRichText method? (I'm having trouble finding the documentation for this 3rd party component) Aug 5 '16 at 12:56
• Thanks! The curious thing is: If I enter tags into the text input box -- directly within the Text Mesh Pro GUI entering the text in the inspector -- then on play the text gets rendered correctly. Side note: yes, the GUI has a toggle to "Override Tags", which I disabled course.
– JBJ
Aug 5 '16 at 13:25

Here we go, thanks for the hint, @DMGregory. By trial and error:

One has to enable rich text before assigning the text to the object. The full commands would be

using UnityEngine;
using System.Collections;
using TMPro;

public TextAsset MainText;

// put this in some function