UI Image color not updating correctly

Hello, I’m using Unity UI Image to display a preview of my level.
I change it’s color from script to change it’s color alpha with two colors I have set in the inspector.
I have done this a lot and it’s should be working.
The code is very easy :

public Image Preview;
public Color ValidColor;
public Color InvalidColor;

...


Preview.color = m_Playable ? ValidColor : InvalidColor;

Even if I change the color of the Image during run time through the inspector, nothing changes on the game view.

This bug happen only on this particular Image class, I’ve never seen that before.

2 Likes

Here is a screenshot of my image and it’s color is set to red through the inspector but it does not change at all …

Anyone can help me with this please :slight_smile: ?

You’re almost certainly hit by Unity issue 1143135: Unity Issue Tracker - Image Color cannot be changed via script when Image type is set to Simple

Simply waiting for a Unity version with the fix should help.

3 Likes

Hey thank you @motorious , this bug drove me crazy I searched a fix for hours.
Is there a way to have notification on bug tracker status update ?
Have a nice day :slight_smile:

Thank you for this response - this behaviour suddently was broken in my game and I could not figure it out. I unfortunately do not have time for unity to figure out how to fix this, so instead I changed my Image Type to Filled (fill amount 1) instead of Simple and the problem was solved.

Thank you again!

1 Like

The issue is fixed on Unity 2019.1.8 :slight_smile:

3 Likes

@Rafarel @LiveOrDevTrying

hey, I am using 2019.1.9f1 of unity still I am facing these issue.
basically I need to change the colors of the scoreboard in my scene, I can change colors for 1 scoreboard (which is basically is an image) but not for the other one, which is exactly the same as the previous.

btw both have the image type as sliced.

1 Like

Version 2019.2.17f1 got issue same trying to change color on my pause panel it’s

not working.

Maybe this will help someone else in future. I wanted to change sprite color from code. found that using Color had no effect but Color32 worked great.
Hope this helps.

16 Likes

For me the solution was quite simple. The alpha was simply set to 0 for some reason. So change the alpha of the new color to 255.

5 Likes

I had the same problem.
In script the range color value is 0->1 and not 0->255.

5 Likes

Can confirm - this worked for me 2019.3.14f1.
Spent 2 hours trying to figure out what I do wrong.

Edit: yeah, only works once. If the color needs to be changed more than once, it doesn’t work.

Thanks. Sounds obvious but I think I just naturally assumed that the Color property set via mono behavior would be the same default alpha value set by unity. I’m ashamed to admit I have spent way too much time on this lol

Like @A_Full said, This is what worked for me.

private Color lowRed = new Color(255.0f / 255.0f, 117.0f / 255.0f, 117.0f / 255.0f);
1 Like

Thanks! I just got hit with it in 2021.1.21f1. And this fixed it. Thanks for posting this fix. Was driving me crazy.

1 Like


If you click on the colour picker in Editor, you can actually see that there is 3 options

  • Color32
  • Color
  • HSV

Which you can see the range of each type.

I tried everything mentioned here, and it still doesn’t work. Any help would be appreciated

That fixed for me. Thank you!

Have you tried the color32 instead of color?