Fading UI Elements

Hey guys, I’m still a little new to the UI system. I am trying to fade text away by adjusting the color’s alpha value. The problem is that my text also makes use of rich text to adjust the color of some part of the text. The rich text colors are unaffected by the alpha color of the text. So my question: is there a way adjust the alpha of a Text UI element without messing with the text color?

Creating a new string every frame manually setting the alpha through rich text formatting is not an option, as the generated garbage would be atrocious.

Thanks!

Is this an assumption or have you actually profiled this? Intuitively I feel like one string per frame shouldn’t be too big of a deal? Afraid I don’t have a cleaner solution to your problem though. =/

1 Like

Well there’s no need to profile it, as strings are immutable, so there will be several bytes of garbage per frame per text element. There may be up to 6-7 text elements at a time. There has to be a way to simply adjust the opacity of a UI element entirely, correct? Perhaps there’s a shader setting somewhere? Sorry, I’m new to the UI system.

Ah, I can see it getting heavier with more than one text element around. And I agree there should be a nicer solution for sure, just the whole “premature optimization is the root of all evil” routine and all. :wink:

CanvasRenderer.SetAlpha() might do the trick.

1 Like

or by attaching and modifying the Canvas Group’s alpha

3 Likes

This worked perfectly, thank you and everyone else so much!

You’re welcome.