Language

How to animate UI Image material in Animation view

I made sprite shader (in graph) allowing me to set outline and dissolve. There is material using this shader and it was set to material property of some UI Image. The main goal is to animate properties (outline/dissolve) of single Image instance.

As I discovered this material works a bit different than Renderer.material - it's shared between all instaces so any changes to material updates appearance of all other instances. Obviously it's not desired behaviour, so I used trick below to make seperate instance:

image.material = Instantiate(image.material);

This part works well as long as property is updated in code like this:

image.material.setFloat("_Dissolve", 0.1f);

What I wanted to do is to use Animation timeline to animate these properties, but there is problem - it's not possible to access material properties. What I also tried to do is make accesor in Image controler script, but they are not visible in animation property list:

I had the same problem with TMPro UGUI text property. I was able to animate it by accessing a method on the animated object via animation event. The method than changed the text. 'So you can animate the outline via animation event. BTW in the Inspector window for animation event first I couldnt find my functions. It's easier/faste to go UP with the arrow in the function-select menu. On the other hand I with this mechanism can't see the animation in the preview. So I am also verrry curious about a better solution.

Hello, the problem I see in this solution, is that you can't animate for example float value from 1 to 0. Also I think corutine would better solution in case of making multiple events. It would be better to avoid it, so question is how to make it differently.