Hi everyone,
I currently have:
- An UI2DSprite.
- A material with a custom shader that I wrote.
As you can guess, my UI2DSprite uses that material.
The shader on the material is simple : given a value, the shader will
lerp between the sprite texel color and a color given as an argument. The alpha is not changed.
In my case, for exemple, given a value between 0 and 1, the UI2DSprite's color will vary between the current color (the UI2DSprite's color) and white (1,1,1,1). Meaning that if I give the value 0 to my material, the UI2DSprite will appear normally. If the value is 1, the UI2DSprite will be a bright white silhouette.
If I set the values for each object containing the UI2DSprite with my material before runtime, everything is great !
Here is my problem :
I am able to change and set the value given to the shader at runtime but the changes are not applied to the UI2DSprite at runtime. If, using the Unity editor, I change the 2D Sprite of my game object (to another 2D Sprite), then the changes given the shader will apply. Otherwise, I can change the value given to the shader all day long and the UI2DSprite will not change at all.
Is this by design or is there a way around it ? I have tried marking the widget dirty (using "SetDirty()") but it is not geometry related, so no success here.
I am not sure but is the issue discussed
here related to my problem ? I tried to apply the solution given in the answer proposed but I realized that UI2DSprite does not have a SpriteRenderer component object to use the function SetPropertyBlock.