- Home /
How to add an AnimatorState to an Animator from Editor script and make it persistent
I am making a tool to help artists build animation sequences faster.... I have ref to Animator in scene, and I have a new AnimatorState created from Editor script. If I try to link this to any other Animator state via animation transitions, UNity complains that my state is not persistent. How can I add my new Animator state to the Animator prefab / asset and have it be persistent, from editor script please. AnimatorState newState = new AnimatorState(); newState.CopyValues( selectedState );
Answer by JonPQ · May 02, 2018 at 09:04 PM
figured it out... Need to use Animator.runTimeAnimatorControllor, then from there get the Asset from AssetDatabase, and can edit that. UnityEditor.Animations.AnimatorController AnimContr = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(MyAnimator.runtimeAnimatorController));
Your answer
![](https://koobas.hobune.stream/wayback/20220612161850im_/https://answers.unity.com/themes/thub/images/avi.jpg)