I’m using this little coroutine to fade away some UI text:
IEnumerator Fade() {
float a = Message.color.a;
float d = a/4f;
float t;
while(a>0) {
yield return null;
t = Time.deltaTime;
Message.color = new Color(1f,1f,1f,a);
a -= d*t;
Y += 15f*t;
RectTrans.anchoredPosition = new Vector2(0f,Y);
}
Obj.SetActive(false);
}
but I notice a severe performance drop on the profiler caused by this function, when only one text element is affected you can barely notice it, but with 6 or 7 elements fading away at the same time, this is what I see:
However if the color remains unchanged, performance remains quite stable, please, notice the fact that I’m also moving the text upwards a little bit, so (theoretically) the rendering algorithm has to recalculate the same amount of pixels on every frame, whether I change the text color or not.
… But!, to ensure the RectTransform is updated at a similar rate than Text, I modified the script assuming deltaTime would remain stable at a rate of 0.02, to increase Y by 1 on every frame.
IEnumerator Fade() {
float a = Message.color.a;
float d = a/4f;
float t;
while(a>0) {
yield return null;
t = Time.deltaTime;
// Message.color = new Color(1f,1f,1f,a);
a -= d*t;
Y += 50f*t;
RectTrans.anchoredPosition = new Vector2(0f,Y);
}
Obj.SetActive(false);
}
I also resized the game window to occupy the maximum height posible (for some reason “Maximize on play” prevents the profiler from recording), to translate every increase of Y into the maximum amount of pixels, but the impact on performance is barely noticeable as you can see below:

