Trying to animate an Image component material/shader

I have a material with a wipe transition shader. In that shader I have a custom property _blendPos that I use to move the shader effect, like this:

my2dSprite.renderer.sharedMaterial.SetFloat("_blendPos", value);

It works fine on a 2D Sprite.

But if i try to assign the same shader/material to an Image component, it doesn’t work:

// Start()
myImageMaterial = GetComponent<Image>().material;
// Update ()
myImageMaterial.SetFloat("_blendPos", value);

I can see the material being updated in the “Project View”. But nothing happens in the “Game/Scene View”.

Help.

In the UI the used material isn’t always the one set in the inspector (we duplicate materials internally for things like stenciling ect). Could you raise a bug on this so we can figure out a way forward to help make this work? You can probably use Shader.SetKeyword on the global scale for the moment, but it’s not the best solution going forward.

@Tim-C Actually, the Image component I was using had a Mask component on it. When I removed it my shader/material worked. Then it’s something related to the Mask component. So in my specific case I think it’s not a bug. But maybe that could work in a mask too, say, to have a mask animation, or just as an effect on the mask’s image. Do you want me to raise a bug on that anyway?

Please do, with a repro.

Done: 629563

Hi,

I faced the same problem yesterday and I couldn’t make it work using Unity 5.3.3, so I think the bug is still there, could you check it?

As IntDev explained, I was trying to apply an animation to the material assigned to an Image component who had a UI Mask component on it. If the Image component was attached to the Mask it didn’t work, if I removed the UI Mask the animation on the material of the Image component worked perfectly.

In my case I took a roundabout and created a material using a shader with a Culling mask and the image to apply to the Culling mask, then applied it to the Image component in order to avoid using the UI Mask, this way the animation works perfectly.

For anyone looking for an awnser on 2020.1.11f1 you need to use: image.materialForRendering

Sorry for the necro;

2 Likes

Unfortunately this doesn’t seem to work in Unity 2020.3.47.
All of my images still update the same colors.