- Home /
"The GameObject or Component is missing!" when assigning an animation curve from script.
AnimationClip[] clips = GetComponent<Animator>().runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
if (clip.name == "fade_out_ball")
{
AnimationClip fade_out_ball = clip;
AnimationCurve curve = AnimationCurve.Linear(0f, 1f, 1f, 0f);
fade_out_ball.SetCurve("", typeof(SpriteRenderer), "color.a", curve);
}
}
GetComponent<Animator>().enabled = true;
GetComponent<Animator>().SetBool("fade_out", true);
I set up an animation, which is attached to a GameObject. However, when trying to assign a curve form script (key values have to change with every instance of the object), it gives me the above warning and won't animate anything. Any idea?
Greetings, Footurist
Answer by albondgames · Feb 19, 2020 at 09:10 PM
Did you ever solve this? @nilsbargmann I'm having the exact same issue and it's super frustrating. Everything about animating in Unity is super tedious and nothing ever seems to work for me.
I've found the solution. I was using "anchoredPosition.y" as my property, but for some reason it needed to be "m_AnchoredPosition.y". I have no idea why, and the documentation doesn't really explain (in their example they use "localPosition.x"). Hopefully this helps anyone else having the same issue (I wasted so much time trying to fix this)