Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

AnimatorOverrideController error, don't change any clips

Discussion in 'Animation' started by FlorentBE, Apr 16, 2018.

  1. FlorentBE

    FlorentBE

    Joined:
    Apr 16, 2018
    Posts:
    5
    Hi,

    In advance, since I'm new, I'm sorry If I'm doing something wrong, I'll try my best do that as clear and precise as possible ! :)

    So I'm having a trouble with the AnimatorOverrideController. I'm trying to create a dynamic spritesheet change. So for example if the skin change it will create the new animations with the new spritesheet and It will then change in the animator the different animation with the one. The part with creating the new animation clip is done and "correctly" done ! :) I'm now trying to change the different state of my animator at runtime. I've searched a lot about how to do that in unity and I found the AnimatorOverrideController, I have my clips, default one in the animator controller and I'm now trying to change everyclip of the controller trough the override controller to put the new Animations clips I created, but I have nothing happening, nothing replaced.

    I'm a bit new to unity, so I'm a bit lost with that..

    Code (CSharp):
    1.     Animator animator; //The animator
    2.     AnimatorOverrideController myOverrideController; //The animator override controller
    3.     // Use this for initialization
    4.     void Start () {
    5.  
    6.         Sprite[] sprites = Resources.LoadAll<Sprite>("sprite/spriteSheet_0326095750"); //Load the sprite
    7.         //ANIMATOR
    8.         animator = gameObject.GetComponent<Animator>(); //get the animator component
    9.         myOverrideController = new AnimatorOverrideController(); //Create new Animator override controller
    10.         animator.runtimeAnimatorController = myOverrideController.runtimeAnimatorController;
    11.         //ANIMATION CLIPS CREATION FOR THE NEW SPRITESHEET
    12.         createBackwardWalking(sprites);
    13.         createRightBackwardWalking(sprites);
    14.         createForwardRightWalking(sprites);
    15.         createRightWalking(sprites);
    16.         createForwardWalking(sprites);
    17.     }
    18.  
    The error is that nothing happen, the clips are not replaced by the new ones.. And I don't know why.. When I try to play a clip it says in the console :


    Animator does not have an AnimatorController
    UnityEngine.Animator:Play(String)
    charachter:Update() (at Assets/charachter.cs:108)



    Thanks :)
     
    Last edited: Apr 16, 2018
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    hi,
    you need to give the base controller to overide

    rather than doing
    Code (CSharp):
    1.  
    2. myOverrideController = new AnimatorOverrideController(); //Create new Animator override controller
    3. animator.runtimeAnimatorController = myOverrideController.runtimeAnimatorController;
    4.  
    create an override controller based on the current controller
    Code (CSharp):
    1.  
    2. myOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    3. animator.runtimeAnimatorController = myOverrideController.runtimeAnimatorController;
    4.  
     
  3. FlorentBE

    FlorentBE

    Joined:
    Apr 16, 2018
    Posts:
    5
    Hi,

    that's the first try I did, but I can't because it says and underline in red AnimatorOverrideControlle r:

    'AnimatorOverrideController' does not container a constructor that takes 1 arguments

    What have I done wrong ? Did I need to update unity or something ?

    Thanks
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    which version of unity are you working on?

    the constructor with one parameter was added in 2017.x if I remember well but that doesn't matter, you can do the same thing like this

    Code (CSharp):
    1.  
    2. myOverrideController = new AnimatorOverrideController();
    3. myOverrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
    4. animator.runtimeAnimatorController = myOverrideController;
    5.  
    and by the way I did a mistake on my first post, shame on me, it should have been

    Code (CSharp):
    1.  
    2. myOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    3. animator.runtimeAnimatorController = myOverrideController;
    4.  
     
  5. FlorentBE

    FlorentBE

    Joined:
    Apr 16, 2018
    Posts:
    5
    Oh yeah I upgraded yesterday, sorry for that I was stil in 5.5.0 x)

    Ok I changed what you told me, and it changes the clip but they are not working in game, I'll see what I have to do to make them work hahaha !

    Is the way of creating them is correct ?

    Code (CSharp):
    1.     void createBackwardWalking(Sprite[] spritesIn)
    2.     {
    3.         AnimationClip animClip = new AnimationClip();
    4.         animClip.frameRate = 60;
    5.  
    6.         EditorCurveBinding spriteBinding = new EditorCurveBinding();
    7.         spriteBinding.type = typeof(SpriteRenderer);
    8.         spriteBinding.path = "";
    9.         spriteBinding.propertyName = "spriteSheet_0326095750";
    10.  
    11.         ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[3];
    12.         spriteKeyFrames[0] = new ObjectReferenceKeyframe();
    13.         spriteKeyFrames[0].time = 0.00f;
    14.         spriteKeyFrames[0].value = spritesIn[0];
    15.         spriteKeyFrames[1] = new ObjectReferenceKeyframe();
    16.         spriteKeyFrames[1].time = 0.01f;
    17.         spriteKeyFrames[1].value = spritesIn[1];
    18.         spriteKeyFrames[2] = new ObjectReferenceKeyframe();
    19.         spriteKeyFrames[2].time = 0.03f;
    20.         spriteKeyFrames[2].value = spritesIn[2];
    21.         AnimationUtility.SetObjectReferenceCurve(animClip, spriteBinding, spriteKeyFrames);
    22.         AssetDatabase.CreateAsset(animClip, "Assets/Resources/animations/backward_walking_new.anim");
    23.         AssetDatabase.SaveAssets();
    24.         AssetDatabase.Refresh();
    25.         myOverrideController["backward_walking"] = animClip;
    26.        
    27.     }
     
  6. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    you're error is probably located there.
    you need to put the name of component properties that you are trying to animate, in this case since it a SpriteRenderer it should be m_Sprite
     
  7. FlorentBE

    FlorentBE

    Joined:
    Apr 16, 2018
    Posts:
    5
    Ooooh ok, I tough it was the name of my sheet, but I misread the function, it is propertyName ^^ Thank you it's working perfectly, I have finally done something more technical with some help I have to admit :p Thank you again :)

    Do I need to pass the thread to solve ? If yes how ?

    :)
     
  8. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    there is no status on our thread, so you cannot officially put a thread as solved, you can close it but it will prevent other users to ask question if needed.

    So left it as is :)
     
    FlorentBE likes this.
  9. FlorentBE

    FlorentBE

    Joined:
    Apr 16, 2018
    Posts:
    5
    EDIT: Sorry, I've found by myself ^^
     
    Last edited: Apr 21, 2018