Question by
unitylepi · Dec 09, 2019 at 03:56 PM ·
c#animationanimatoranimator controller
AnimationOverrideController does not set clip.
I have a project with a character that has an animation controller attached with two states (state1 and state2). state1 is a walking animation and state2 is empty (none). I use the following code to try and set a clip to state2, but state2 -> motion stays empty.
public GameObject tstCharacter;
public AnimationClip tstClip;
private Animator anim;
private AnimatorOverrideController animOverrideController;
void Start()
{
anim = tstCharacter.GetComponent<Animator>();
animOverrideController = new AnimatorOverrideController(anim.runtimeAnimatorController);
anim.runtimeAnimatorController = animOverrideController.runtimeAnimatorController;
// anim.runtimeAnimatorController = animOverrideController;
}
void Update()
{
animOverrideController["state2"] = tstClip;
// animOverrideController["Base Layer.state2"] = tstClip;
}
Comment
Answer by unitylepi · Dec 09, 2019 at 06:16 PM
Apparently you need to replace a clip name, not a state name, which makes this feature much less useful. Haven't found a way to simply change the motion clip on a specific state. My states start out with none as motion so that won't work... sigh...