CrossFadeAlpha and CrossFadeColor not working for Text Components.

Hey everyone I did a brief test with Unity 4.6 and it seems that CrossFadeAlpha and CrossFadeColor aren’t working in Text Components.

Can someone let me know if I’m doing something wrong or if this is indeed a bug and, in that case, I’ll open the ticket.

Here is my code:

I added a text component and made it’s alpha 0. Doing this I should be able to fade-in the text.

gameObject.GetComponent<UnityEngine.UI.Text>().CrossFadeColor(Color.white, 1f, true, true);

//This also doesn't seem to work

gameObject.GetComponent<UnityEngine.UI.Text>().CrossFadeAlpha(1f, 1.5f, false);

Any feedback would be greatly appreciated.

Cheers

Hi what color is the text to start with? (I’m guessing black). This crossfade fades the color on the CanvasRenderer. This means that if the text is black you will be doing “black * whatever color” which is still black.

If the text is white then it will be “white * whatever color” which is whatever color.

Don’t know if you are still having this issue; however, I was running into a similar problem before viewing Tim C’s response.

If you haven’t notice the alpha value in a components color tab does not change, after using crossFadeAlpha.

That being said, are many different ways to get around what you are trying to do. Set your components with a max desired alpha in your editor.

On Awake() run
gameObject.GetComponent<UnityEngine.UI.Text>().CrossFadeAlpha(0f, 0f, false);

Now you can raise and lower your alpha using crossFadeAlpha in your code as you need.

1 Like

Weird, same thing with RawImage. CrossFadeAlpha to 0 (or 1) at Start then you can manipulate it accordingly later on.

Thanks!

This is a common point of confusion — Graphic.CrossFadeAlpha does not operate on the color of the Graphic (the Image component in this case), like you might expect. Instead it operates on the alpha of the CanvasRenderer component, which is easy to overlook since it’s not a very accessible property. (It’s exposed only via the GetAlpha and SetAlpha methods, and not visible in the Inspector.)

So the best thing to do is call GetComponent().SetAlpha(0) in the Start method (no need to use CrossFadeAlpha here). Then you can use CrossFadeAlpha to tween it back in.

3 Likes