Hi guys i had this problem too after some testing i can say that it does work for me but not as expected.
What i did as a test for **fading in** was to set [CrossFadeAlpha()][1] "**duration**" parameter to more extreme values, i choose 1000 and it faded fine.
Like this:
`_myImage.CrossFadeAlpha( 255 , 1000 , false ) ;`
When **fading out** it seems that the "**duration**" parameter works as described in the [Unity Docs][3] .
So i set it like this : `_myImage.CrossFadeAlpha( 0 , 1 , false ) ;`
I’m having the same problem with fading in (incrementing the alpha), but none of the workarounds did the job for me. So I wrote a Coroutine for the fading, which works for UI Text:
And It is called as StartCoroutine(FadeText(textObjectName, 0.25f, 0.5f));. It could also be extended for other Graphics. Not extensively tested, but working for my cases.
Hope this can be useful, and any comments on improving it will be very appreciated.
CrossFadeAlpha() not working with Image.color !!!
It is working with
“the alpha of the CanvasRenderer color associated with this Graphic”.
So, first you need to do: image.CrossFadeAlpha(0f, 0f, true);
or image.canvasRenderer.SetAlpha( 0.0f );
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 you should keep your Graphic color fully opaque, but call GetComponent().SetAlpha(0) in the Start method (since there is no way to set the CanvasRenderer alpha in the inspector). Then you can use CrossFadeAlpha to tween it back in.
I too did performed tests and the CrosFadeAlpha() only seems to work for Fading out not for fading in. To be more accurate, it works for fading in, but not as intended, is not honoring the delta time for doing the fade in. It just jumps to the fade in alpha value passed on.
If it looks like there is only 2 conditions of transparency (0 and 1), it is probably bad shader choice.
To use UnityEngine.UI elements, like SetAlpha or CrossFadeAlpha, you need to choose one of those UI shaders in materials you are using for UI elements.