Bug changing text color

So I found a strange bug, I haven’t been able to solve after trying around for some time.

When I added the code for changing the color of the text with the label.color = defaultColor method, as soon as it applies it breaks the text and remains invisible, only visible by a red outline that appears when selecting it. It then remains broken and I can’t get it back to have color (in Play mode or just in the Scene view). The only way I found to recover from that was deleting the whole Text (TMP) object in the Tile prefab, and creating a new one. Although when running the game the same issue happened again.

The color break just when going back to Unity after coding it, so to prevent the issue from appearing in the Editor I moved the ColorCoordinates method to only go through if the application is running. So now the issue only triggers when going into Play mode, although after exiting that mode the issue remains as described earlier.

Any ideas? Is this a known issue?

Engine version: 2021.3.1f1

Ok, I tried adding the default initialization for the colors in the code, and now it works properly. Do the Color variable always need to be initialized in that way? Can’t it work just with the Serialize and picking a color in there, with no defaults?

I know exactly what is happening since I’ve fall for it so many time that it is frustrating lol.

If you see closely under the color block in the ‘Inspector’, there’s a thin black line underneath whatever color you’ve chosen. That’s is the alpha value of the color you’ve set. Unity will always initialize this alpha value to 0 hence any color you pick will always be transparent.

Now click on that color block, under R, G, B there’s an A bar, increase the value to maximum 255 and your color will be fully opaque and you can see them now.

1 Like

Oh lord, I actually saw that black line as a difference against a newly created one, but couldn’t figure out if it was actually the alpha or what.

Thank you so much, you saved me from a road of pain and suffering. :sparkling_heart:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms