- Home /
can't animate MeshRenderer.Material._Color property
Hello all, I'm trying to animate a material color of an object in run-time, I simply want to fade it from a color to another (ex. Black to white).
In the console i get this error as soon as I try to change the color value in the animation inspector :
Getting control 9's position in a group with only 9 controls when doing ExecuteCommand
And if I try to play the animation it just doesn't change the color, but everything else works (it's an articulated anim). While I see this warning in the material inspector :
MaterialPropertyBlock is used to modify this values
But i don't see this property in the animation inspector. Now, I could try animating the material through scripting, maybe I can change color values by lerping or using iTween, but I would prefer doing it through the built-in animation inspector. Is there a way to do it?
In case there is not, could you please give me some directions to take, to do it by scripting? I would like to change the value from/to various colours so it would be useful to create something like a function like
void switchColor( Color to) {
// Color from = Material.color;
// SomethingLikeLerp(from, to, 1);
}
But I can't get how to fade to another color by value, since colors have alphanumerical codes.. Thanks in advance for the answers, I already checked other answers, but they all were referred to unity4 or not giving me hints.
Answer by MilanGM · Jul 21, 2016 at 04:29 PM
In Animation window if you want to change the color of MeshRenderer, you have to add that property manually since it's not exposed in the Editor. You have to click:
(Button) Add Property → (Select your object from hierarchy) → Mesh Renderer → Material._Color (+)
Then you have to manually add key frames and manually set values (or edit curves)