Search Unity

Mecanim runtime animation

Discussion in 'Editor & General Support' started by flycode, Dec 3, 2012.

  1. flycode

    flycode

    Joined:
    Dec 3, 2012
    Posts:
    3
    Hi, if the mecanim animtion system supports runtime change animationclip in unity4?

    for exsample, i have two animator states, StateA is normal animations, it has a blendtree that holds animationclips like idle, walk, run. and StateB has only one animationclip like attack(which in Motion or maybe in blendtree -- only one animation node), at runtime, i want to change the animation in StateB.

    i have search the whole scripts api, and find nothing(the interfaces are all read only).

    thanks very much.
     
    Last edited: Dec 3, 2012
  2. zhangjiq

    zhangjiq

    Joined:
    May 17, 2012
    Posts:
    17
    I want to know this too...
    Mecanim is good, but if Unity marks old animation "lagacy", macanim should be able to do everything the old animation system could.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    You cannot change clip at runtime for now. This is something we want to add in a future release.

    The old animation system won't be remove before Mecanim can handle everything it was handling.
     
  4. flycode

    flycode

    Joined:
    Dec 3, 2012
    Posts:
    3

    thanks. Waiting for this future~~~~
     
  5. huang

    huang

    Joined:
    Aug 16, 2012
    Posts:
    34

    can i replace a animator controller achieve this ?
     
  6. Ramillienovitch

    Ramillienovitch

    Joined:
    May 30, 2013
    Posts:
    1
    It has been more than a year since you posted your message and I wanted to know if this feature will be available in a near future.

    Thanks
     
  7. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    It should be available in the next point release 4.3
     
  8. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    Can we now add and remove motion clips with the new 4.3 at runtime? I've been looking through the API and can't see anyway to achieve this. Such a basic thing missing from mecanim yet required for customisation systems.
     
  9. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    yes you can, you must use the AnimatorOverrideController component.

    you can create your AnimatorOverrideController in the editor or at runtime.
     
  10. alvaro-em

    alvaro-em

    Joined:
    Feb 23, 2012
    Posts:
    77
    Hi, this is the closest thing to documentation I have found so far about AnimatorOverrideController (very bad, Unity guys!). Could you please add some extra lines of code about how to actually using it to change the "motion" property of an AnimatorController state? I coulnd't figure out how to do it!

    Thank you very much in advance!
     
    Last edited: Nov 27, 2013
  11. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Sorry I think I misunderstood your question. You cannot add or remove clip at runtime, but you can override clips with AnimatorOverrideController.
    By example if you have a controller with a clip 'run' you could override the clip 'run' like this.

    RuntimeAnimatorController myController = animator.runtimeAnimatorController;
    AnimatorOverrideController myOverrideController = new AnimatorOverrideController();
    myOverrideController.runtimeAnimatorController = myController;

    myOverrideController["run"] = myRunFasterClip;

    // Put this line at the end because when you assign a controller on an Animator, unity rebind all the animated properties
    animator.runtimeAnimatorController = myOverrideController;
     
  12. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Hello guys.
    The point is to be able to add and remove clips at runtime. We can't make a system generic enough if mecanim can't do this, and to be honest while its great, that "non-generic enough" is the reason I guess about 80% of people still use infamous so called "Legacy"

    I'd really like to use mecanim. I do, but I can't
     
    Thorlar likes this.
  13. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Sorry for reviving this post but this the only one I found that got close to a solution.

    So in theory, to achieve the idea of adding and removing clips we first must create a dummy Animator controller and add the number of clips that could potentially be used as "slots"?

    I've been trying to get around that idea any way I can, as its a bit counter intuitive for my end user.

    The request for my toolkit to allow for Mecanim is enormous. I had to answer "why legacy" so many times I even made a review of Mecanim back on Unity 4.2.
    After the promises on version 4.3 I was really hoping I could switch to Mecanim. There has to be a work around to be able to add clips without working with the visual editor.
     
  14. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    CWolf likes this.
  15. elhongo

    elhongo

    Joined:
    Aug 13, 2015
    Posts:
    47

    This example would be great to have in the Unity Documention
     
    Thorlar likes this.