Unable to set animation curve for Material

Hey folks, I’m an animator and have been building a tool to automate some of the more mundane tasks I have to do in my everyday work.

I’ve made a custom Editor window with a bunch of different options. I’ve gotten almost everything working like it should, with the exception of setting curves for material properties. (_Color, MainTex.offset.x, etc)

I run a function that creates and applies an animator, creates a clip, and then loops through all children and adds curves for position, rotation and scale, if desired. I’m also wanting to add curves for material properties, but I’m failing. :slight_smile:

When I reference the documentation for setting a material curve -
clip.SetCurve (“”, typeof(Material), “_Color.r”, curve);
I get yellow keys with (missing!).

When I manually record a change, I see the path is different. (see attached photo)

I’m using AnimationUtility.CalculateTransformPath to get the path, and it’s working when I set keys for transforms just fine.

I’ve been googling a crap ton, but as of now, haven’t been able to figure out just exactly what I’m doing wrong. Any help would be hugely appreciated. Thanks!

2911846--214717--setcurve.png

The documentation specifies that second parameter of SetCurve() is the type of the component whose property is to be set. Material is not a component type. But MeshRenderer is, and that’s probably what you want, with “Material._Color.r” as the field to set. Just like in the line of your image below the yellow line.

1 Like

Andy, thanks for the reply. I figured it was probably that, and I have tried different combinations such as clip.SetCurve (“”, typeof(MeshRenderer), “Material._Color.r”, curve);
Which looks right when I run the function, but still says missing. Hmmmmm. I’ll keep at it!

2912054--214729--setCurveNew.png

for anyone else having the same problem, I was able to fix using clip.SetCurve (“”, typeof(MeshRenderer), “material._Color.a”, curve); Lower case m was the key.

1 Like