Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Does mecanim actually work for you?

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

  1. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I'm retrofitting a game I made for a client a couple of years ago, for the client again, and we're replacing the statemachine characters and entire animation system I built with mecanim.


    But what I'm finding is that my own was much more stable, and that mecanim is garbage.

    I have talking animations with idle animations in between them (you press a next button to go from idle into the next speech animation) and mecanim keeps skipping right through animations randomly. So out of 10 speech sections, sometimes it skips number 7, sometimes it skips number 5, sometimes it gets jammed on an idle and doesn't change.. Its killing me.

    I highly don't recommend mecanim. I waited years for it to mature but even now its not making the grade. After weeks of blaming myself and days of playing the exact same sequence over and over with different buggy results, I'm prepared to go on the record and say if you've got an alternative, use it.

    How is it going for you? same issues anyone? Anyone have these issues and resolved them? Anyone got any tips for explaining to their client why they just lost 5 grand on investing in a faulty unity feature?
     
    kalamona likes this.
  2. melkior

    melkior

    Joined:
    Jul 20, 2013
    Posts:
    199
    I've had some problems with Mecanim also!

    I'm writing a dungeon crawler and Mecanim was really hard to work with - I gave up and had to use the Legacy system which was straightforward and easy to use.

    I've had all sorts of problems with the root motion system, even with all the googling and forum searching and toggling all the settings my models were either sinking through the floor , walking in the air, or jiggling around in place when they should be idle.

    Hypothetically if I had grinded enough hours of work I might have figured it all out - but really? Should that be necessary?

    Why is Legacy animation system so straightforward that I had it working within an hour after giving up on two weeks of Mechanim work?
     
    kalamona and AaronC like this.
  3. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Generally no problems with it as far as characters/animation, a bit of wierdness with UI elements. It works well enough to use in production, but lots of room for improvement.
     
  4. voltage

    voltage

    Joined:
    Nov 11, 2011
    Posts:
    515
    Mecanim is not the future for me. If Legacy is ever filtered out, I'd be Very upset.
     
  5. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Its not very user friendly but it does work. If you are able to pull out anything you can't disclose I'd be happy to take a look at a sample with you state machine and the code driving it.
     
  6. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    i never develop high budget realistic game. The only part of mecanium for me is humanoid feature. Other than that, I can only experience its inconvenience.
     
  7. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Works perfectly for me, and I'm using it pretty extensively with retargeting and layering.
    If it doesn't work chance are you set it up badly. I am using 4.6 mecanim, don't know if 5.0 has become worse.
    The only improvement I would like is some sort of live feedback for the muscle settings, as it is a pain to do trial and error when you retarget.
    Every time I need to setup avatars, save, go to editor play, discover the settings are wrong, return to avatar editor, repeat ....
    I am talking about things like foot spacing,etc.
     
  8. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    I have no problems with it. I usually set up an array of boolean switches to match the states and a respective strings array of the same parameter names as Mecanim uses. I then just loop through the boolean array at each request for a state change and when i get the boolean match I use that index int to extract the index method parameter name and send that to Mecanim. I can precisely control states without querying Mecanim for current state or transition info and guarantee I am i only one state at a time. I do agree with @00christian00 above about realtime muscle visualization..It would help immensely in retargeting to certain characters...especially from the huge mocap libraries to my own custom characters. With the addition of pole vectors/ knee and elbow hints I now can do all the procedural animation tricks and systems I learned over 15 years in doing procedural and reactive rigging in C4D. Would like to see direct IK control over the root and body IK instead of the MatchTarget system. It would make implementation of parts of my IK toolset mush easier and be in line with how one may control sic i a 3D app. Like putting a circle spline controller around the pelvic root that the pelvic root would match the position and rotation of when manipulated.
     
    andreiagmu and frosted like this.
  9. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Can it be controlled by a custom built state machine? Instead of having mecanim have its own triggers, can you programmatically do all of the transitions? I'm sure its creators won't appreciate us forcing it to operate like the previous systems, but meh. I'm going to start caring about animation soon and that means touching mecanim at some point.
     
  10. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850

    @Tomnnn I kind of control the Mecanim state machine though the mini state machine loop functions I mentioned. When you get into Mecanim if you need any hints or a hand feel free to PM me. Anything for a fellow jester:)
     
    andreiagmu and Tomnnn like this.
  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Yes, you can. I actually do this with one of our assets and it works very well. It makes for a very clean state machine without you having to explicitly set transitions between every state. I only use a small set of generic parameters and transition systematically with Animator.Play or Animator.Crossfade. You can then group the animations into different substate machines and not have to explicitly add a single transition unless you want to.

    Animator.PNG

    Jump.PNG
     
    andreiagmu and Tomnnn like this.
  12. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,789
    Everytime I try and get into Mecanim I end up going back to the legacy animation system. It's getting to the point though where I really need retargeting and root animation, and everytime I get going into Mecanim I want to jump out a window. The legacy system can be set up and tweaked so easily... anybody know if there's a way to do retargeting, or at least root animation without Mecanim?
     
  13. bluescr

    bluescr

    Joined:
    Sep 7, 2014
    Posts:
    21
    It's certainly got some nice bits, but let down by areas where you simply don't have enough control over it.

    It feels like you're never really in control. You can't directly force it into specific states immediately. You have to ask it nicely, and it might do it within the next frame or two. Last time I tried you just had no direct control over an active state/anim - for example, to directly set the position within a clip or even just change the speed of a single state (rather than global playback speed)

    I also found it surprisingly tricky to write scripts that work with Mecanim. Things like determining when a state was being entered/left - or even if a 'polite request' to change state (via a trigger or boolean) had actually happened. Could use some OnStateEntered/Exited callbacks

    The showstopper for our project though was being unable to assign/swap animation clips at runtime withing an existing animation controller. We ended up with a main character that uses a mix of Mecanim and Legacy animation...

    Seems that there's some improvements in 5.0 that may have addressed some of the above issues. But as a mobile developer, I suspect I'll be using 4.x for a good while yet.
     
  14. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    http://docs.unity3d.com/ScriptReference/Animator.Play.html
    This has been around for a very long time, probably around 4.3.
     
  15. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    It doesn't guarantee that the change occurs on the current (or alternatively on the next) frame though which I think was @bluescr 's point.

    For example if you have a single frame animation and play it with Play() before calling the next you are not guaranteed to have the short animation play for 1 frame without another animation also playing (depending on other factors it may play for 0 or it may play for 2, or it may play for 1 frame but another animation might still be active and blended in too).
     
  16. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Animation Baker
     
  17. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,789
    Doesn't animation baker just bake out new animation files? I'd love to be able to simply use animation clip A on both humanoid object B and humanoid object C at the same time, dynamically.
     
  18. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    If you want total control use :
    http://docs.unity3d.com/ScriptReference/Animator.StartPlayback.html
    It stop the animator and you can drive the animation yourself with the play method. Once you want to put it in "auto" mode again,call stopplayback. Use the methods in lateupdate that gets called after any animator evaluation.
    By doing so you can also alter the speed of the animation as you want.
    That's all.
     
  19. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    The point is not that you can't workaround Mecanim, the point is that you have to. What if I want to directly Play an animation on one layer whilst leaving the normal transitions going on another layer (for example Play my weapon attack animation on my upper body layer mask with frame level accuracy, but leave the normal moving animations transitioning as usual).

    Again as I've already said, Mecanim works, it just takes a bit of work (a bit more than you would expect) to get it to work.
     
    melkior likes this.
  20. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    PS Thats not how StartPlayBack works. StartPlayBack is only for playing back recordings as it says in the doco. As soon as you try to set back playback time without a recording you get an error. So although you should be able to use this as a hacky way to play a single frame, it does not allow you to "drive animations" or "alter the speed of the animations" that are called using Play()*

    * except by first recording the animator doing them in the first place and then playing them back
     
  21. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    I know for sure since I am using it to drive a animation by arbitrary speed without any previous recording.
    All it does is pause the animator. Then you can tell the animator to reproduce a very specific position at every render frame, the more animation frames you skip the faster it will go...

    Too many people is expecting Unity to create the game for them. Do you want advanced things? Then you need to work your ass for it, they can't cover every single scenario. It's still a game engine, what many wants instead is a level editor...
     
  22. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    Yeah what I find is I start ending with dozens of connections and my animation count is fairly low.
     
  23. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Try looking at my procedural IK system in evaluation for release at the Asset Store soon. I am just finishing up handgun point and shoot mode and am adding a right over-the-shoulder cam mode for the combat cam controller to match and then I will be doing a Walk-Run Cycle generator and Obstacle nav mode. Or a kick punch fight mode. The goal is to eventually remove all animations for any navigation and combat modes and have umpteen styles created with just the adjustment of a few key slider params.. The link is in my sig file.
     
  24. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Thanks much for confirming this. Setting things up in the editor then using them programmatically is definitely something I'm interested in for when I plan to introduce a new plague unto the world that is... my anti-art in motion!
     
  25. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Ahh .. are you only playing single frame animations and not setting playbackTime? Because as soon as I set playback time to something other than zero, in even the most trivial test (single state, with a single long animation), it throws an error.

    - - -
    EDIT: Played a round a bit, so I can set frame with Play() but not using playback time... good to know.
    - - -

    Just FYI I laready solved all of the issues I mentioned long ago. I'm not lazy, I'm just able to acknowledge that if something so simple takes code based work arounds then its not ideal. Mecanim is supposed to enable ANIMATORS to create animations. If you have to code all your animations to get proper control then something is wrong.

    @ippdev your system looks awesome, been meaning to buy it anyway, but I don't think you would appreciate it if I embedded it in my own assets :)
     
    Last edited: Jun 27, 2015
  26. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    With legacy system, I'm able to setup a generic (custom) statemachine which by just changing animations in the inspector, I can generate many different type of creatures.

    When I switch to Mecanim, what I see is the motions are hardcoded, and I cannot change them at runtime, so if I have 100 creatures, and I decide to change the state machine, I have to change 100 state machines. How do you guys handle it?
     
  27. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Mecanim works great, definitely good enough for production.

    That being said, it operates very differently from how you would do legacy animation and the UI is not the best. It's frustrating that you can't zoom, menus are weirdly organized, some workflows can be hard to understand, tons of confusion in trying to find what you want in the API, etc...

    But once you finally get the hang of it and give it what it wants it works pretty great. I almost dont mind dealing with the downsides entirely because of Blendtrees.
     
  28. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    You can do this with Mecanim. The one caveat is that you _may_ have to change the Transition blend..or not..I have used both. With Legacy my scripts would get long as biblical scrolls. With Mecanim I use 3 arrays and a couple of functions for the same level of control...one page as it were.
     
  29. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Can share how you did it?
     
  30. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    I never understand why people port a perfectly working game into a new system just because it's there?

    But anyways...

    Mecanim seems quite good once you get the hang of it. Well, what I like best is that you can apply a human avatar to two characters and then apply animations from one to the other. So it's great for that. It would be even better if there was not just a human avatar but a bi-ped avatar or more avatar plugins.

    The reset of all the state machine thingamewhatsits I haven't delved into too much. I don't much see the advantage of that over scripting. But some people like visual programming so there you go.

    Tip: One thing that tripped me up early on was that I had a transition coming out of "Any state" which was triggered every second or something. Don't ask me why. Anyway. I deleted it and all was fine.
     
  31. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    +1
     
  32. TheSin

    TheSin

    Joined:
    Aug 4, 2011
    Posts:
    150
    A huge issue for me in the past and before 5.0 was lack of control in mecanim from my own systems and random bugs which caused transitions to fail etc....The only thing I love about mecanim is the retargeting. I have everything else available without it ie fsm behaviours ( with way more control), inspector Events and a node based hfsm with way more control for transitions.

    Mecanim has tried to simplify a lot of things by giving less control...this eventually makes things complicated as you attempt to work with coding alongside it all.
     
  33. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    That comparison doesn't really work since scrolls are also technically 1 page ;)

    In this case, it's to write less code. In other cases, it's for a 1% performance boost. We go back and forth so things are easy to work with and as efficient as possible. There's probably a lot of pressure on this industry to keep as up to date as possible :D
     
  34. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Set up the Animator. You want the rig to do this..then that..then the other...for navigation blend trees you can get your walk-.jog-.run-.yadda yadda left then right.. idle walks backward, strafings and use the speed and direction be controlled by the H and V of the inputs.. Speed would then be the Y axis of the 2D Freeform BlendTree and X would be the Direction. Name these with a capital for easy reference in the Parameters dropdown and of course make them a float and assign them to the BlendTree parameters sliders. Test the animation blend by watching it and adjust till its sweet dragging the red dot in the BlendTree 2D graph window.. Allot easier than the old system. Make all your animation connections..Duck...Crouch...Jump..etc.. Name the parameters in the dropdown selecting boolean.

    To set up your scripts create an array of Strings that match all the Animator booleans names exactly. Set up a matching array of ints. Set up a matching array of inputs. If you use .KeyCode you can rebind your keys in the Inspector. Set up h and v floats. Control those from the Input Horizontal and Vertical Axis values assigned to h and v which translates to the Animator as Speed and Direction when you pass them.

    In your Update loop set up your input controls and boolean conditionals related to the boolean state transitions in the Animator parameters.. Then make your functions to control which state it is in and keep everything in a logical order
    Code (JavaScript):
    1. var animator : Animator;
    2. //CONTROLLER MODES
    3. var controllerModes : String[] = ["Idling", "FreeNavMode", "StanceMode", "ObstacleNavMode", "FightMode", "DamageMode", "HandgunMode"];
    4. var controllerModeInt : int;//THE INDEX OF THE MODE
    5. //
    6. var debug : boolean;
    7. function Start () {
    8.     //GET A REFERENCE TO THE COMPONENTS
    9.     if (!animator) {
    10.         animator = GetComponent.<Animator>();
    11.         if (!animator) {
    12.             Debug.Log("You need to add an Animator Component to this Avatar.");
    13.         }
    14.     }
    15.     //sets the Controllers initial mode to FreeNavMode if not set in the Inspector
    16.     if (currControllerMode == "") {
    17.         controllerModeInt = 1;//easy reference to the mode you may want elsewhere
    18.         currControllerMode = controllerModes[controllerModeInt];
    19.         SetControllerMode (currControllerMode);
    20.     }
    21. }
    22.  
    23. function Update () {
    24.      //conditionals go here
    25.      //input axis code here
    26.      //assuming you have decided to change mode to FightMode
    27.      SetControllerMode ("FightMode");
    28. }
    29. function SetControllerMode (ctrlMode : String) {
    30.     for (var i = 0; i < controllerModes.length; i++) {
    31.         if (ctrlMode == controllerModes[i]) {
    32.             controllerModeInt = i;
    33.             currControllerMode = controllerModes[controllerModeInt];
    34.             animator.SetBool(currControllerMode, true);
    35.             if (debug) {
    36.                 Debug.Log("currControllerMode : " + currControllerMode);
    37.             }
    38.         } else if (ctrlMode != controllerModes[i]) {
    39.             animator.SetBool(controllerModes[i], false);
    40.         }
    41.     }
    42. }
    43.  

    HTH
     
  35. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Thanks but I don't understand what your solution is. think we are talking about different things.

    In the old system, my own statemachine, say has Idle, Walk, Attack states. I can expose the AnimationClip on Inspector, and create different creatures by changing the animations. This is what I'm trying to do with Mecanim, 1 state machine but the motions can be replaced.
     
  36. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    I think you'd have to pre load every state you had hoped to use into the statemachine imtrobin.

    FWIW I solved my issue by giving up on getting Mecanim to reliably deliver me out of one state into the other and settled on using animation events to call functions that set triggers and then it seemed to be a lot more solid getting me from A to B rather than A to B and then randomly to C .

    I do think animation events are the best thing since sliced bread.
     
  37. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    I'm not referring to states, but motion (animationclips in legacy). States are fixed in the animator but I don't want to create one for each creature.
     
  38. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    My biggest gripe with Mecanim is that I have no idea how to setup it with Blender and I wasn't able to find good tutorial on that on the web. All animations I've done (bone-based or just transforms in blender) ends up putting character to (0,0,0) for some reason instead of applying all movement relative to current position.

    My game has animations, but it is done purely in code, I also try to avoid more complicated characters because of that.
     
  39. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    The solution controls the states the Animator is in and is like a switchboard that allows one call to go through only. Use SubState Machines and BlendTrees. Want Creature01.. Set Creature01 Boolean to true and transition to that SubState Navigation BlendTree. You are making it harder than necessary by clinging onto your old processes like a piece of chair from the Titanic deck. Setting up BlendTrees and SubState machines are trivial compared to the amount of work to sync previous legacy anims. You can blend precisely down to 1/nth of a frame. I was always guessing by 10ths of a second what the proper blend length was in Legacy. Now I can see it and adjust on the fly while the animations are looping. May be that I did alot of node based setup in 3D and image processing apps that made it easy as pie to get going. I think Mecanim is a blessing and saved me dozens of hours in set up and control. Fact is.. yer gonna have to stick to legacy forever and whatever version number they stop supporting it at or learn how to use Mecanim.
     
  40. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850

    You don't set it up "with Blender". Just import your FBX and split to animations then drag and drop those on the State Machine and set up your transition blends and conditions as well as floats for speed, direction etc. in the BlendTree 2D graphs. If they are in place animations then uncheck Root Motion..Otherwse use Root Motion. If not using Root Motion then move the character using MovePosition and MoveRotation.
     
  41. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    I don't see how your solution scales to 100 characters, and I don't see why you need need to respond with that kind of attitude.

    Anyway, I found something that seems promising, but looks like a strange way.

    http://forum.unity3d.com/threads/mecanim-change-the-motion-of-a-state-in-code.179541/#post-1475888
     
  42. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    AnimatorOverrideController exists for your exact situation.

    The Playables API in 5.2 also provides a way to play animation clips on objects without getting an entire AnimatorController involved.
     
    hopeful likes this.
  43. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    What kind of attitude.. Using colloquialisms? Forgive me for being colorful if so as I am just a salty old codger. I will reply in drab format to you in the future. Or stating facts about Legacy going to be deprecated? You are making it harder IMO. YMMV.
     
  44. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Sorry, still don't understand anything.
     
  45. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    Where do you get stuck?
     
  46. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Do you mean you've animated walking in Blender, as in walking in space not place, but in Unity when the animation plays, the character stays at 0,0,0?

    Btw, I admit I don't use Mecanim much, and its a bit disobedient, but I like it far more than the legacy system. I switched as soon as it came and never looked back. Everything works for my use, but there's a few quirks that can be worked on.
     
  47. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    No, I mean that no matter where character is, whether I'm using legacy or mecanim character is teleported to (0,0,0) when actually trying to play animation. Also I don't know how to "cut" blender's animation, which are done in straight line for Mecanim. I need good tutorial for it and I can't find any.
     
  48. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,850
    The teleportation is weird. Would have to see the code you use to drive it. To cut up your animations open them in the Animations window. There will be a timeline with start and end markers. Pull them to the appropriate positions whilst running the animation in loops. When satisfied with the one you are separating, click the little + sign and add another one and name it. Do the same with the markers. If looping check the Loop and Loop time boxes and check the Y position box so that your character knows their is gravity and where the feet should be. Check any Use IK boxes you see along the way. Use Root Motion on the Animator component if your animations are not In Place...i.e. they actually move and not like yer walking on ice.
     
  49. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I used to get that with Legacy animations exported from Carrara as well as several assets I purchased. Turns out there was some sort of root motion attached to the animation that always moved it back to its origin. The only way I found to get around that was place it at 0,0,0 and then make it the child of an empty game object and move the empty. You could try that to see if it is an issue with root motion or not. You could also try turning off the root motion of the animation clips to see if they still move back to 0,0,0. If not, then that is the problem and you'll need to figure out how to export from Blender without the root motion. Not the best solution if you use Mecanim root motion to move them.
     
  50. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    You nailed my biggest complaint which is lack of insight into what the current state actually is, and being able to just force it into a state.

    Overall it just doesn't add that much value by the time you factor in all the stuff you have to workaround.