Bug with rich text <color> tag?

So I have this line of code:

UIManager.instance.ShowHintMessage("You've unlocked <color=green>" + doorTarget.doorName + "</color> door.");

As you see, it’s calling a method called ShowHintMessage which receives a string parameter from a singleton. I use it very frequently for showing messages on screen and I never had an issue with it. Before seeing the code, I’ll like to go deeper on the situation.

I discovered literally a few days ago about the rich text function on UGUI text, so I decided to take a look a it a see how it worked. On this (“You’ve unlocked <color=green>” + doorTarget.doorName + “ door.”) line, I was trying to change the color of the “keyword” of my message, and well, it did change, but the behavior was very weird.

The message it’s displayed with a fade in/out effect. This is how it’s supposed to work:

7011496--829477--fine_gif.gif

but as you can see from the next gif, the keyword (doorTarget.doorName) it’s staying on screen even after the fade out effect:

7011496--829480--bad_gif.gif
*edit: I just recently noticed that the keyword appears even before the fade starts

Now, let’s take a look at the code:

public void ShowHintMessage(string message) {
        StartCoroutine(IHintMessageCoroutine(message));
    }

    IEnumerator IHintMessageCoroutine(string pass) {
        DOTween.Restart(hintMessageText);
        //hintMessageText.canvasRenderer.SetAlpha(0f);
        hintMessageText.text = pass;
        hintMessageText.DOFade(1f, 1f);
        //hintMessageText.CrossFadeAlpha(1f, 1f, true);
        yield return new WaitForSeconds(2f);
        hintMessageText.DOFade(0f, 1f);
        //hintMessageText.CrossFadeAlpha(0f, 1f, true);
        yield break;
    }

I was first using DOTween for the fade in/out effect, but the issue mentioned before appeared, so I tried with CrossFadeAlpha because I thought that maybe it was a compatibility issue. Actually, if I use CrossFadeAlpha I get another problem, the text doesn’t even appear!

So, I’m not sure if that’s intended behavior (don’t remember seeing anything about it in the docs), or if it is a bug.

didn’t read, just seen the gifs.
I think the problem is that the tag not only defines the color but also the transparency of the content. therefore it is unaffected by alpha-changes.
What you can do instead is making the text a child of a canvas group and animate the alpha of the canvas group instead.

1 Like

Well, that’s kinda sad. I’ll give it a try and see what happens!

Well it worked, but still, I guess I’m not changing the flair because this behavior is not clear on the docs (honestly, I’m not sure if it is actually documented at all).

Note: on Rich Text | Unity UI | 1.0.0 (unity3d.com), there’s a table with tags. On the color tag, there’s a part that says:

So, that makes me thing that somehow I would need to specify the opacity? Still, not so clear.

you can specify the opacity but you don’t have to. if you don’t specify the opacity it will automatically assign full opacity.