Help me work around a bug, please

Does anyone know if it’s possible to override an image component’s functions?

I’m trying to figure out a workaround for a bug in 2019 that breaks an image component if you try to change it in script. Basically

Image.sprite = newSprite;

Makes

Image.color = Color.Black;

Do nothing.

I’ve submitted the bug (https://issuetracker.unity3d.com/issues/image-component-not-responsive-to-color-property-change-when-source-image-property-is-changed-via-script),

but am finding it really hard to work around, and it destroys some of the core features of my game. So I was wondering if there is a way to hijack calls to image.color (set) so I could clear and reassign the sprite back to itself after any color change.

Yes, I could create a separate monotype to do this and add it to every image, but I’d like a solution that’s easier to clean up.

Does anyone know if there is a way to do this?

Yes, color is a virtual property from the Graphic base class: https://bitbucket.org/Unity-Technologies/ui/src/a3f89d5f7d145e4b6fa11cf9f2de768fea2c500f/UnityEngine.UI/UI/Core/Graphic.cs?at=2017.3

You should be able to do something like:

public class MyImage : Image
{
   public override Color color
   {
       get { return base.color; }
       set
       {
           base.color = value;

           // now do your custom stuff here
       }
   }
}

and then replace all of the Image components with MyImage components and the rest of the UI functionality should work 100%. Sprite, however, is not a virtual property so if you need it the other way around it may not work. You could overcome that by listening for the graphic and layout events that follow when a UI element is marked dirty and defer your logic to that point. I do this in my own project, not to override the color, but to deal with the way masking materials works.