Search Unity

Beginner's question about AnimationClips / Avatar

Discussion in 'Animation' started by deLord, Aug 23, 2015.

  1. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    Hi

    Boy, I tried to understand this a million times during several weeks but I never got the grips onto it. So hopefully one of you can finally help me out.

    I am not creating my own models but I buy them. So far, with the animation type "Legacy" of the model import, I didn't have big problems, except I never understood how to retarget animations. Now I need this feature and changed the animation type of one of my models to "Humanoid", which was preselected when I imported it.

    For my tasks it suffices to use a simple Animation#CrossFade() to blend between animations. Perfectly OK.

    When I use legacy, I can call the Animation component with animComp.CrossFade("idle") etc and it works. But with the Animator component things are different. The model I imported provided an avatar and an Animation Controller as well (and all animations of course).

    Q1: When using avatar and Animation Controller, do I NEED to define every single animation(clip) as a state? If that is so, why does the provided controller only define 1 (default) state? The model I am talking about has over 50 animations and I doubt I need a state for every single animation. If so, it should be provided, right?

    Q2: How can I simply call the clips I want when using the avatar/controller scheme? How can I know which animations exist if I dont have the animation component? Where are the references to the clips?

    Q3: How can I retarget an animation from a different model of the same provider to the other model? Both are humanoids.

    I watched a whole lot of videos and read the doc, but there must be a twist in my head or sth ;) please help me, thanks
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    The simple answer is yes, you need to define every clip as a state.

    The more complicated answer is that you need to define every state as a state. A state often corresponds to a single clip, but it can also be a blend tree or a sub-state machine.
    • A blend tree is a combination of different clips. For example, you might have a blend tree for movement that blends standing, walking, running, and sprinting clips, all based on the value of a Speed parameter. The whole blend tree is a single state.
    • A sub-state machine is a state that contains child states and the transitions between them.

    Call the states, not the clips. You can use Animator.CrossFade("state-name") to manually switch to another state, or set parameters using Animator.SetTrigger("trigger-parameter-name") etc. to change states using the transitions you've set up in your animator controller. This is actually much more powerful than legacy animation because you can, for instance, set a Speed parameter and trust that the animator controller will do the appropriate thing such as transitioning from idle to walking to running.

    Generally speaking, you can drag a clip from any Humanoid model onto any Humanoid's animator controller and it should work fine.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  4. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    If what Tony says is true, that means I would have to define 50*49 state transitions. How stupid would that be? Is there no alternative?

    @Mecanim.Dev this command on my avatar model gives me a list of size 1 and not 50. Maybe b/c there is only 1 state?
    If I add a state it gives me 2.

    So this controller can be thought of "ok we know it sucks, but create this thing once and then re-use it for every humanoid that you import" ? I mean, let's say I dont want transitions (which I said), where is the advantage over the legacy system? AND: can I retarget with the legacy system?
     
    Last edited: Aug 24, 2015
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    You don't have to define any transitions. Drop all 50 clips onto the animator controller canvas. Then use Animator.CrossFade("state-name"), just like you would use Animation.CrossFade("clip-name") in the legacy system.

    • Blend trees
    • Sub-state machines
    • Root motion
    • Animation retargeting
    • Visually see what's going on in each layer at runtime in the Animator view
     
    theANMATOR2b likes this.
  6. deLord

    deLord

    Joined:
    Oct 11, 2014
    Posts:
    306
    OK thanks, I will try it out and see how/if I can retarget my animations
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,692
    I forgot to reply about this. No, you can't retarget with legacy.

    You can also mix-and-match transitions and Animator.CrossFade(). For example, say you have a list of "bored" states (crossing arms, tapping feet, looking around, etc.). You could define transitions from these states to your main idle state. Then you can call Animator.CrossFade() to play a specific bored state and forget about it; the transition will automatically return you to the idle state when it's done.