'Issue with changing colour in image component of button [Unity2D/ UI]

When I change the image colour component via the code, I am getting an issue where it is changing the colour of the button but not displaying it.

I have put a GIF so you can view exactly what I mean. It recognises from the code that I have changed this but it's not displaying in the inspector until I click it as shown in the GIF. I have put my code below, not sure if it will help in anyway.

Prefab setup for the button:

public Transform CreateButton(string content, UnityAction _event, float r, float g, float b, bool overrideCheck = true)
    {
        Transform ButtonHolder = CreatePrefab(EditButtonPrefab);
        ButtonHolder.GetComponent<HorizontalLayoutGroup>().padding.bottom = 0;
        ButtonPrefab.GetComponentInChildren<TMP_Text>().text = content;
        ButtonPrefab.GetComponentInChildren<Image>().color = new Color(r, g, b);
        Transform _buttonCreated = CreatePrefab(ButtonPrefab, ButtonHolder);
        _buttonCreated.GetComponent<Button>().onClick.AddListener(_event);
        if (overrideCheck)
            ContinueButton = _buttonCreated.GetComponent<Button>();
        return _buttonCreated;
    }

This grabs from other places but then I can call this function and put in the necessary requirements. So for the example I was showing, each of these buttons will have different colours.

CreateHeaderText(null, pageNumber + "/" + totalPages, "How well did you communicate with the rest of the team?");
            CreateButton("Not at all", delegate { AddNewExperiencePage(pageNumber + 1); }, 255, 112, 112);
            CreateButton("Little", delegate { AddNewExperiencePage(pageNumber + 1); }, 255, 167, 112);
            CreateButton("Moderately", delegate { AddNewExperiencePage(pageNumber + 1); }, 255, 236, 112);
            CreateButton("Good", delegate { AddNewExperiencePage(pageNumber + 1); }, 155, 255, 112);
            CreateButton("Very good", delegate { AddNewExperiencePage(pageNumber + 1); }, 112, 255, 126);

Any thoughts would be great to hear. Not came across this myself before. Any help would be greatly appreciated. I will post below how I am implementing this as well.

Thanks :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source