Unity replacing > character from string

I’m trying to use rich text, following the documentation exactly but it seems there is a bug (using 2018.3.0f2) where it replaces the greater than character from my markup tags with a less than character. For example if I type:string boldTxt = "<b>I want this text bold</b>"; then unity prints <b<I want this text bold</b<

Is there a workaround for this?
edit: Rich text works if I type the tags into the the inspector but I’m trying to use a script

I haven’t encountered this issue. Are you putting it into a textmeshpro text or a regular Unity text?

You could put an @ in front of your text which may solve the issue, but > is not a special escape char, so it shouldn’t make a difference.

string text = @"<b>I am text</b>";

I’m using regular Unity text. Tried the @ in front, didn’t make a difference.

edit:
I’ve tried delegating the string, I’ve tried replacing the ‘>’ with > and then .Replace(“>”, “>”) and still no luck.

Could you post the whole code? Maybe the string gets modified somewhere else. I am using 2018.1.3f1 and it works fine if I am doing it like this:

string txt = "<b>hello</b>";
    // Use this for initialization
    void Start () {
        GetComponent<Text>().text = txt;
    }

SOLVED (somewhat)

Thanks for testing with2018.1.3,

So I made a fresh script and UI text element just to make sure there was nothing else effecting it and low and behold the code I posted is working from that script something was effecting it. The tag.
An appended color tag with spaces. <color = green> should be <color=green>. Taking out the spaces fixed it. But here’s where it gets weirder. I can’t recreate the flipping around of the greater than sign on the new script. If I leave spaces it simply prints out the as is. So I never did figure out what’s flipping the greater than character into a less than. So weird… But I’m accepting this as a mystery and moving on since taking out the spaces from the color tag worked.

Glad you could solve it, though those things are a nightmare because you never know when it it come again to haunt you
I would suggest you try out TextMeshPro since it is part of Unity and gives much clearer text and a ton of options. For example I used it to make links in the text that show info boxes when hovering over it.

1 Like