- Home /
AnimatorOverrideController not working
I don't know if I'm using this right. I have an animation controller with many clips in it. But there are a few exceptions where I might want to replace the idle clip with something else, or the idle and combatIdle clips with something else, but I'm just trying to get one to work for now. The important thing is that all clips that make a transition back to idle will make their transition back to the replaced clip. In searching for a solution, I came across the AnimatorOverrideController, which seems like it's supposed to do EXACTLY what I need. However, in testing, all models with the replacement controller still use the old idle. I tried a few different things:
//assuming animCont is my main animation controller
var anim=obj.GetComponent<Animator>();
var overCont=new AnimatorOverrideController(animCont);
overCont["idle"] = Instantiate((AnimationClip)Resources.Load("anim/guardidle")); //this resources load isn't null; it does load a clip so that's not the problem
//overCont[overCont.animationClips[0]]=overCont.animationClips[1]; //I've tried this too, idle is in position [0], but when I did this, idle didn't become the second clip at [1].
overCont.name="guards";
anim.runtimeAnimatorController=overCont;
When I do it by name, as above ["idle"], I wasn't sure if it needed the name of the clip or the Motion (as defined in the animation controller) so I tried both and neither worked. idle is the motion name and longidle is the clip name. And, of course, specifying the clip instead of search by name didn't work either (commented out above). Nothing has any effect whatsoever. I'm using Unity version 2017.3.0f3.
Any ideas? Thank you!
before helping here code wise... why don't you create the override controller in the project view, assign it the actual controller, modify the clips you want changed and then assign it to the models you need it on? resources folder is used for small files and especially for files you might not use, but it sounds like you definitely do.
I kind of mislead people by referring to "models" above. In reality, my human characters are dynamically generated. Just certain types of humans will have different animations (like guards in this case). I get what you're saying about creating the override controller at design time though. I'll try that and use that controller ins$$anonymous$$d (for guards) and see if that works. As long as I can, then, modify the base controller and the changes will take effect in the override controller for guards without me having to change both every time. There will be more than two in the end so I don't want to have to maintain a bunch of different animation controllers when they only vary slightly. I really should be able to do this all programmatically. I'm not sure if I'm running into a Unity bug here or not. I'll let you know if I get anywhere.