I am creating Animator OverrideController via script based on current controller assigned to animator component. I have created animation curve for position and it works. When i try to animate transparency (material color alpha) it does not work (it does not make any effect, however in Animation Dopesheet there is yellow line: "Object name : Material.Color.a (Missing!)"). Did I fail to properly access this property or is it the consequence that creating animation via script works only for legacy animations with Animation component?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationScript : MonoBehaviour {
void Start()
{
AnimationClip clip = new AnimationClip();
AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, transform.position.x, 1.0f, transform.position.x);
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
curve = AnimationCurve.Linear(0.0f, 1.0f, 1.0f, 0.0f);
clip.SetCurve("", typeof(Material), "_Color.a", curve);
Animator anim = GetComponent<Animator>();
AnimatorOverrideController animatorOverrideController = new AnimatorOverrideController(anim.runtimeAnimatorController);
// "loop" is the name of clip not name of state
animatorOverrideController["loop"] = clip;
anim.runtimeAnimatorController = animatorOverrideController;
}
}
However analogous code for legacy Animation component works:
void Start()
{
Animation anim = GetComponent<Animation>();
AnimationCurve curve;
// create a new AnimationClip
AnimationClip clip = new AnimationClip();
clip.legacy = true;
// update the clip to a change color
curve = AnimationCurve.Linear(0.0f, 1.0f, 2.0f, 0.0f);
clip.SetCurve("", typeof(Material), "_Color.a", curve);
// now animate the GameObject
anim.AddClip(clip, clip.name);
anim.Play(clip.name);
}
What am I missing and why is first script not working?