UI Button not changing colours

Hello, everyone :slight_smile:

I have a small bug in my current project which affects a specific button. What I mean is that I have other buttons in the same scene which do not share this bug. I thought it may be an issue with the button I’ve created, so I made a new button from scratch in the same place in the scene heirarchy, but it also retained the bug.

The issue is as follows:
I have a script which changes the color of the button based on some text value, which is called every Update:

private void ChangeButtonBasedOnTitle(GameObject titleObject)
    {
        foreach (KeyValuePair<string, int> title in titles)
        {
            if (title.Key == titleObject.GetComponent<TextMeshProUGUI>().text)
            {
                if (PlayerPrefs.HasKey(title.Key) == false)
                {
                    myButton.GetComponentInChildren<TextMeshProUGUI>().text = title.Value.ToString();
                    myButton.GetComponent<Image>().color = new Color(248f, 104f, 104f);
                }
                else if (PlayerPrefs.GetInt(title.Key) == 1)
                {
                    myButton.GetComponentInChildren<TextMeshProUGUI>().text = "Equipped";
                    myButton.GetComponent<Image>().color = new Color(150f, 255f, 129f);
                }
                else
                {
                    myButton.GetComponentInChildren<TextMeshProUGUI>().text = "Equip";
                    myButton.GetComponent<Image>().color = new Color(255, 231, 129f);
                }
            }
        }
    }

The script works as intended - it changes the color of the Image component of the button. However, during runtime something strange happens - the button appears white despite the fact that its Image component has the colored value:


I’ve noticed that changing the Normal Color value of the Button component changes the color of the button completely, but I’m pretty sure that’s just what happens when a button is white and its normal color value is changed.

Has anyone encountered this before? Any idea on how to fix it?
I can workaround by changing the Normal Color field, but making whole Color Fields seems a bit drastic.

Thanks in advance!

Color values should be floats 0-1, not sure if that makes any difference (since somehow it works in editor?)
new Color(248f, 104f, 104f);

can test with Color32(248f, 104f, 104f); if want 0-255.

Doy! It really was the fact that I put in values like 248f and not 248f/255f.
I can’t believe I missed that. Thank you :slight_smile: