Material not updating on Image

I am updating the texture of a material on runtime, and you can see in the inspector that the material color changes like it should, but the changes don’t update on the UI Image unless I edit any property on the Image (like enabling & disabling Raycast Target, Maskable, setting color or source image), what is happening?
The texture on the Material is a black-green gradient

The texture of the image remains black-white, which is how it was from the start. I can’t attach more images but if you edit any property of the Image, the white part will turn green.

I’ve tried both img.material.mainTexture = texture and img.material.SetTexture(), same result with both.

I do not recommend to directly change material properties of UI elements but img.materialForRendering is probably what you should use since Graphic component internally copying your shared material. You can also try to request for canvas update after modifying material properties.


I just ran into a similar issue in which I am editing a texture (due to some image processing with OpenCV) and I want to display it on screen using a UI element. I do not know whether this is expensive but the way I found to make it work is to let the image component know the texture has changed.

This is how I managed to get the texture updated, by calling “SetMaterialDirty”:

public Image image;

void Update()
      if (Input.anyKeyDown)
            ModifyTexturePixels(); //Some code that modifies the texture

Hope it helps