Search Unity

Does mecanim actually work for you?

Discussion in 'General Discussion' started by AaronC, Jun 25, 2015.

  1. mr_blahblah

    mr_blahblah

    Joined:
    Jan 15, 2016
    Posts:
    38
    I'm necroing this thread as it's still relevant - find mecanim unfinished, buggy, and I've wasted too much time on it. I'll never use it again - Unity devs take note. Mecanim should be stamped with a big, red warning saying 'DO NOT USE', as it's a massive timesink to discover just how broken it is.
     
  2. zyzyx

    zyzyx

    Joined:
    Jul 9, 2012
    Posts:
    227
    Or you can report the bugs. I rather have them fixing bugs than wasting time stamping warning signs on things.
     
  3. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    It's been over 3 years and I still haven't made the jump to Mecanim... :D
     
  4. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    The system I'm working with now has a 3rd person view and has a lot of animation blending.
    • Mechanim = Crazy Awesome

    The previous system I used was all "one off" animations with very little blending.
    • Mechanim = Bad
     
    angrypenguin likes this.
  5. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Works great for me. What issues are you having?
     
    zombiegorilla likes this.
  6. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Same. Haven't noticed any bad issues. Maybe I'm not doing anything too complex.
     
  7. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    This... :D
     
  8. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I am and consider it much easier to do complex animation sequences in mecanim than legacy. Besides, how awesome is it that the models don't need to have an identical skeleton to use the same animations?
     
    resequenced, angrypenguin and frosted like this.
  9. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    There were some bugs in 5.2, but has been pretty solid since then. We are using it for fairly complex things.
     
  10. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Its pretty awesome! And it'll get even more awesome when they introduce the same for non humanoid skeletons. Read they're working on it in the roadmap. I think it said retargetting for generic, but I think that's what it meant.
     
  11. Aabel

    Aabel

    Joined:
    Nov 4, 2012
    Posts:
    193
    Mecanim is awesome! It's definately got some quirks to watch out for but so far all my problems have been self inflicted. Frankly Mecanim is one of those features that keeps me using Unity.
     
  12. telecaster

    telecaster

    Joined:
    Jan 6, 2013
    Posts:
    29
    I am having issues using it. It is probably me, but being now 4 days into it (not that long you may argue) I am still unclear on some aspects. Transition timings and effects on animation completeness. I have 4 basics animations (idle, turn left, turn right, jump). I used Maximo for free to do the basic rigging and animations, and they look great in the preview in Unity. I dragged all 4 animations into the mecanim view, created boolean variables to control entry and since then nothing works quite right.
    a) The turn animation is 90 degrees in the preview and in the animation itself on Maximo, but in Unity with mecanim it is 100 degrees and varies slightly each time. I have tried setting transitions to 0 but it makes no difference. There should be a simpler form of simply triggering the turn exit after completing 90 degrees turn (1 run of animation)
    b) the jump animation is executed without the forward movement. No idea how to get that sorted outside of scripting (again, in Maximo this is actually a forward jump and carries the appropriate data.
    c) Control states vary (ie Boolean variables are not returned automatically back to false (and the return to idle is not triggered) at the end of a single animation run through. Again I had to script.

    I am frustrated that this is taking me so long. Am I missing the right lessons here for simple stuff? I downloaded examples including the free unity asset, but nothing deals with accuracy. In my scenario 91 degrees is no acceptable. The turn has to be perpendicular exactly. So Now I am considering dumping the mecanim aspects and simply script the whole thing and be done with it.

    Any thoughts, suggestions and hints are welcome. mecanim.jpg
     
  13. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    I'm having issues too but with animation events being skipped. Should be fixed in 5.5. As for your case, are you using trigger parameters or actual booleans? Triggers sound good when you think about it, but they're actually just controlled booleans and don't work as most of us feel like they should.

    What are your conditions for transitioning from idle to turn and from turn back to idle?
     
  14. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    If transition duration isn't working, you need to check in import settings whether the root motion is taken from correct bone. By default it uses something weird (pelvis?), you'll need to ensure that rotation and movement is taken from "root" bone.

    Vertical motion in jump would require special handling, basically, if you're using animated jump movement and want jump to perform exactly the same motion as stored in animation, then you will need to disable gravity and switch rigidbody to kinematic for duration of the clip. This can be done by writing State Machine Behavior.
    https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.html . By default character will not be able to perform animated jump by itself, because well, it'll be falling down because of gravity. Normally jump is done as adding vertical velocity to the char and animatior handles "mid-air" jumping loop. See 3rd person controller for examples.

    If you want boolean to reset, then instead of boolean you need to use trigger. However, once you fire the trigger, it'll stay "stuck" until state machine processes it. This might not be what you want.

    Keep in mind that mecanim is not precise. Normally animation like locomotion is done via a blend tree, and if you need incredible precision (like turn using exactly 90 degrees), you might need a different solution. Legacy animation system might be worth checking out, although I haven't used it.
     
    angrypenguin likes this.
  15. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Thanks for that. I was doing that but within the player controller Monobehaviour. And also changed the player collider height. The gravity could be done on button press, but the collider height uses a curve which doesn't take effect during transitions, but using a state machine it apparently does.

    Code (CSharp):
    1. public class JumpingSMB : StateMachineBehaviour
    2. {
    3.     public Rigidbody myRig;
    4.     public Animator anim;
    5.  
    6.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    7.     {
    8.         myRig.useGravity = false;
    9.         anim.ResetTrigger("Jump");
    10.     }
    11.  
    12.     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    13.     {
    14.         Vector3 center = myRig.gameObject.GetComponent<CapsuleCollider>().center;
    15.         center = new Vector3(center.x, anim.GetFloat("JumpHeight"), center.z);
    16.         myRig.gameObject.GetComponent<CapsuleCollider>().center = center;
    17.     }
    18.  
    19.     override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    20.     {
    21.         myRig.useGravity = true;
    22.     }
    23. }
    As far as I understood you also have to assign the myRig and anim through an Awake or Start function, you can't drag and drop them it won't work.

    That's why I use "ResetTrigger". Since I only want it as a one-off thing. Could also use a bool in such way but yeah. Still a learning process. lol
     
  16. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    Last time I was writing StateMachineBehaviors, I was grabbing components I need from "animator" parameters, instead of storing them in fields that are visible in inspector.That's because StateMachineBehavior is not attached to your in-game object, but to animator controller node, which can be used by multiple game objects. So if you want flexibility and more than one animated object, you'll need to get desired component using "animator" parameter you received in OnStateEnter/Exit/Whatever.

    I'd highly recommend to take a look at ThirdPersonController and tear it apart. Instead of trying to make character jump according to animation, default unity thirdpersoncontroller simple comes in "midair" animation loop that has no root motion and when character jumps, it adds vertical velocity. This kind of approach is simpler. It also demonstrates how to properly play "landing" animation.
     
    Martin_H, angrypenguin and ChrisSch like this.
  17. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I don't use mecanim at all, icky icky. I do understand some of how it works. I just don't like the workflow.
     
    GarBenjamin likes this.