Cannot change Image color [2020.2.1f1 Personal]

I cannot seem to change the color of an Image now. First I thought it’s because I hadn’t assigned it a sprite, but after assigning it a sprite, it still didn’t work.

I took a look at the documentation of Color and it said it expects the value to be between 0f and 1f, so I changed it to that and it still didn’t work.
Looking at one of the answers in Unity Answers, someone said that using Color32 solves the problem. It didn’t. (Yes, I did put the RGBA values of Color32 between 0 and 255.)

Then I found a bug in Unity Issue Tracker that says it only happens if your image type is “Simple”, so I modified the sprite a bit and set the image size to “Sliced”. (which doesn’t give any warning/errors in the inspector/console)

It didn’t work.

I found another post in Unity Answers that said that it is because the sprite is black.
The sprite I made, however, was a completely white 1x1px square. (and I set the color in the inspector to be dark blue)

----- Additional info -----

  • Yes, the inspector does modify the color of the image.
  • No, the code doesn’t give an exception.
  • Yes, I made sure the color values are in the expected range (0f to 1f for Color, 0 to 255 for Color32)
  • No, the beginning color of the image wasn’t white, it was dark blue and I tried to change that color to white using a script.
  • No, I didn’t accidentally drag and drop the wrong image.
  • Unity version: 2020.2.1f1 Personal
  • Windows OS: Windows 10 64-bit
  • CPU: 4-core @ 3.5GHz
  • RAM: 4GB

Can anyone help me?

Thanks in advance!

(The important part of the) code:

[SerializeField]
private Image targetImage;

public void Update() {
    targetImage.color = Color.white;
}

Sounds like you’ve done a good job of checking for all the most common problems.

I suggest that you add a Debug.Log statement to your script to verify that it’s running at all. While you’re at it, maybe make it print the value of targetImage.color before you change it; see if the value is what you expect.

Is there a Button component involved at all? Buttons that use color-tint transitions (which are the default) will mess with the color of their target Image in order to show the button’s state. (Which wouldn’t necessarily cause your problem, but would be another thing to check.)

Is there a prefab involved at all? Sometimes people accidentally use a reference to a prefab asset instead of to an instance of that prefab in their scene, or things like that.

oh wow I can’t believe I misclicked on the checkmark of the script, no wonder it’s not running
I’m really sorry.