Question by
kbop2000 · Apr 10, 2020 at 07:08 AM ·
editoreditor-scripting
Remove Animator in clip via Editor Script?
i need this .. help
Comment
Best Answer
Answer by kbop2000 · Apr 13, 2020 at 06:09 AM
it work. this code
void RemoveAnimatorInClip(Animator target, AnimationClip clip)
{
var controller = target.runtimeAnimatorController as AnimatorController;
string removeName = clip.name;
var stateMachines = controller.layers[0].stateMachine;
stateMachines.defaultState = null;
if (stateMachines.states.Length - 1 < 0)
stateMachines.states = new ChildAnimatorState[0];
else
{
List<ChildAnimatorState> list = new List<ChildAnimatorState>();
for (int i = 0; i < stateMachines.states.Length; ++i)
{
if (stateMachines.states[i].state.name.Equals(removeName)) continue;
list.Add(stateMachines.states[i]);
}
stateMachines.states = list.ToArray();
}
AssetDatabase.SaveAssets();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(controller));
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612231004im_/https://answers.unity.com/themes/thub/images/avi.jpg)