- Home /
Animator Controller created by script is not recognized by Animator
Hey everybody, I seem to be having trouble creating an Animator Controller through script that the Animator will actually recognize.
A bit of context: I have a custom editor that allows me to add new entries to a list of NPCs that spawn in the game. In order to save a bit of time, I'm also having it create empty animations and an animator controller assets to use with the new characters. I do this with the following code:
AssetDatabase.CreateAsset(new AnimatorController(),"Assets/Sprites/Unit Sprites/Animations and Controllers/New Unit Animation Controller.controller");
While this does indeed create a new controller, when attempting to open it in the Animator I'm greeted with "Cannot show controller from asset bundle".
I use a near identical script to create new animation assets without any problems, so I'm really not sure what I'm missing here?
I have the same issue, when using the alternative function
CreateAnimatorControllerAtPath(string path)
or
CreateAnimatorControllerAtPathWithClip(string path, AnimationClip clip)
An object is created, but it is not recognized by the Editor. Because of this, I am unable to access the controller in the editor or modify it via an editor script. Does anyone know why this happens?
Answer by maxoulaf · Dec 02, 2016 at 06:26 PM
I just had the problem and found out that it was only because the controller created by script does not have any layer.
You can fix it either by adding manually a new layer after you've created your controller, or adding this code :
AnimatorController controller = new AnimatorController();
controller.AddLayer("Base Layer");
AssetDatabase.CreateAsset(controller, pathNewAnimator + ".controller");
Answer by HeyJoeLang · Oct 13, 2015 at 11:29 AM
I found the answer. It was much simpler than I was making it out to be. The datatype is not assumed when the function is called. You have to add ".controller" to the end of the path.
For example:
UnityEditor.Animations.AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/AC");
should instead be:
UnityEditor.Animations.AnimatorController controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/AC.controller");
Hope this helps.