I have an Image component that uses a shader with secondary texture and color.
If I try to update them using material.SetTexture and SetColor it has no effect unless I disable the Image component and enable it using ‘enabled’
Creating a new material and changing the settings on that also works.
I’ve tried calling Image.SetMaterialDirty and Image.SetAllDirty but they made no difference
Is there some call I’m missing to tickle the state or am I updating the material incorrectly?
What does your code look like?
I’ve managed to make a small project to repro the issue. It appears that the Mask component causes the issue. I assume that the modified material with the stencil settings is not getting regenerated when I change the Image.material parameters
I’ve attached the project. If you play the scene in the editor and select the Canvas/Panel/Panel object you can toggle the tickle parameter on the TestShader component to change the behaviour - tickle on causes the material to update. tickle mask just sets the shader texture mask, it has no effect on the bug (I was trying to pin down what did have an effect)
I’ve also noticed the Mask/stencil buffering does not behave well with RenderTexture, but I haven’t pinned down what my exact issue is yet.
2936274–217189–ImageTest.zip (31.8 KB)
Is that test package useful?
Not sure if you ever figured out the issue, but I just spent some time on the same thing.
The Mask object causes a modified material to be returned so it is no longer rendering the texture that you are updating with the “material” property. Using set on the materialForRendering property will set the correct material if a mask is involved.
So line 51 should be
m_image.materialForRendering.SetColor(“_HazeColor”, color);