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

Mecanim Control

Discussion in 'Assets and Asset Store' started by Mistermind, Jan 24, 2014.

  1. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    163
    Great, buying it right now and at such a low price! It's hard to believe that Unity has not added this functionality yet.
     
  2. Kecske85

    Kecske85

    Joined:
    Apr 19, 2013
    Posts:
    8
    Hi!

    Any ETA on the next version?

    Did you go with the blendTrees, or is it a completely different approach?
    I'm asking because I need a "Blend" method that would allow me to play a blend between two animation clips.
    I was thinking of adding this myself, pretty much the way you described a month ago, replacing the two states with blendTrees, but instead of "animating" the blend variable from 0 to 1, I'd expose it instead.
    This would let me have smooth aiming for various attack animations (shooting, stabbing, punching ...etc) with just 3 "key" animations for each: up, straight, down.

    Should I wait for the next version or will it be a lot harder to add blending to it?
     
    Last edited: Apr 9, 2014
  3. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844

    Hey there,
    Unfortunately the solution I found uses a library that is currently hidden, and it turns out you cannot compile your project if you are using hidden libraries like this one. According to Unity's upcoming features, I believe they will probably release these libraries as public on Unity 5, but we gonna have to wait and see. In the meantime I can add this new system as a .zip file inside the next update just so you guys can see the approach taken.

    As for blend trees, this approach may also work on the new system, but it will require some minor modification on this new script. While the current Mecanim Control dynamically updates all states on the State Machine upon animation request, the new system basically creates all states dynamically at the start, meaning you can technically have your own blend tree set at that state machine before running the game.
     
    Last edited: Apr 9, 2014
  4. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Mecanim Control 1.0.3 sent to the Asset Store,
    - Minor bugs fixed on the current version
    - Added a zip file under the Scripts folder containing Mecanim Control 2.0

    Mecanim Control 2.0 have a few extra methods and debug information, but the key feature is the ability to dynamically create a state machine and all its required states at the startup. Unfortunately the methods used to do this are from a hidden library from Unity, and because of this it cannot be compiled into a build.

    For those interested in checking out, just open the zip and replace MecanimControl.cs script under the Script folder. No extra configuration needed. Mecanim Control 2.0 also doesn't require any external assets, meaning the script itself can be imported into any project with no dependencies.
     
  5. KrayonZA

    KrayonZA

    Joined:
    Mar 5, 2013
    Posts:
    52
    Awesome thanks, will check it out and post feedback :)
     
  6. Kecske85

    Kecske85

    Joined:
    Apr 19, 2013
    Posts:
    8
    MMind check your private messages please!
     
  7. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Hey there Kecke85
    Sorry I've been a bit busy these past few days. I'll get back to you on that as soon as I can
     
  8. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    This looks like a very needed tool, but I don't want to ditch some of the features that make Mecanim state machines useful. For example, I have a 2D blend tree set up for movement, and it works superbly; is it possible to use it with Mecanim Control?
     
  9. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Using the current approach unfortunately it isn't possible, but using Mecanim Control 2.0 there might be ways. Unfortunately version 2.0 uses hidden Unity libraries that can't be compiled into a build. MC2 is currently available in a zip format inside the package. Unlike MC1, you don't need any extra files to operate. The script is 100% independent.
     
  10. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Which ways would work with 2.0?
     
  11. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    MC2 works by dynamically creating a state machine and adding all the necessary states based on the animations listed.
    Since that process happens at startup, and, unlike MC1, it doesn't modify its structure afterwards, you can technically modify the code so instead of creating a new state machine every time it simply uses one that was already created.
    This is just a theory since I haven't had the chance to try that out yet, but I believe its the way to go.
     
  12. Wrekk

    Wrekk

    Joined:
    Jul 16, 2012
    Posts:
    51
    I will be able to use animation retargeting with your system, right?
     
  13. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Yes. An example of that in action is right here:


    This example shows Mecanim Control implemented in another tool, but you can see how I'm retargeting the animations by simply changing the avatar and prefab of the characters.
     
  14. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Hi ! first i would like to say that your idea is REALLY great Many thanks!


    but, how can I enabled IK using this system ? i mean even activating IK Pass in resource animator controls its not working, i guess everyone would need to make somethings with heads and hands IK, how this is possible to be achieved ?

    Many thanks
     
  15. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Hi there! thank you!

    For Foot IK, you can adjust the states themselves inside each controller. You can find the controllers on Resources/controller(1 to 4). As for manually setting the IK using animator.SetIKPosition, I never tried. If you tried it and it didn't work, chances are its because of the way MC1 works (dynamically swapping between animator controllers). If that is the case, you can try using version 2.0 (available in a zip file inside the build). Just remember that MC2 currently uses certain libraries that cannot be compiled on Unity 4. They will probably be available on Unity 5.
     
  16. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Hi! thanks for answering ! but no , it dont work, but is not for foot ik , its for head and body look at, i go in your controllers and click IK Pass as unity says, but dont work
     
  17. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    I'm using MC2 so i don't get the glitch issue. However i noticed a problem with the SetSpeed() methods in that they don't accept negative values! Is this a bug or is there another way to make an animation reverse. For example i want to take a walk forward animation and turn it into a walk backwards animation using SetSpeed("Walk",-1f) . However if i try this the animation still walks forwards.

    I have tried using the Rewind() method but it does not work either. The first loop it begins to reverse the animation then it seems to be causing a repeating glitchy loop which is very slow.

    Analysing the code it seems that the speed is being put through a Mathf.Abs(speed) method which removes the negative value. Is this a bug or is this intentional on the developer's part?

    Can someone help with this issue please?

    It seems that the only work around is to bake in a walk backwards animation.
     
    Last edited: May 11, 2014
  18. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    i have look like trouble with currentAnimationData

    NullReferenceException: Object reference not set to an instance of an object
    MecanimControl.FixedUpdate () (at Assets/MecanimControl/Scripts/MecanimControl.cs:73)

    i have try initialise my animation and controler set not start

    $8JwYt.png
     
  19. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Technically speaking MC2 should take care of that. Since you can't set the speed of the animator to a negative value, I made it so every clip has a mirror and a negative copy of itself. When you set a negative speed, MC2 will try to call on the negative state of that animation, even blend into it if you need it.
    I haven't used MC2 in a while (I had to work on some compilations lately) but I remember it was working just fine. I'll try running some tests on it when I have the time. Honestly MC2 is far superior to MC1 in terms of what it can do. Unfortunately we need to wait on Unity's next update and hope for the best =)

    Humm I'm not sure what version of MecanimControl are you using. On mine, line 73 doesnt seem to match to the related error. Can you copy line 73 for me?
     
  20. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    if (currentAnimationData.timesPlayed == 0 MecanimControl.OnAnimationEnd != null)
    it's comming from WrapMode
     
  21. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Humm. Are you using the latest update?
     
  22. joanllobera

    joanllobera

    Joined:
    Aug 20, 2013
    Posts:
    2
    hi,
    this tool seems very useful.
    I would like to have access not only to its functionality
    but also to its source code to see how it is implemented.

    In this forum it says the source code is provided free, but then i look into licenses and it seems that to get the source code of mecanim control i need to purchase the full source code version of the UFE. Is this correct, or the mecanim control asset comes already with its source code?

    Thanks,
    Joan
     
  23. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Hey there Joan,
    Mecanim Control is completely open source. Don't worry about it. The only place its not open source is on the PRO version of UFE,
     
  24. MichaelHF15

    MichaelHF15

    Joined:
    Mar 25, 2014
    Posts:
    50
    I could use some help with this... I can get my controller script to find all the animations, and it seems to actually play the first frame, but that's just it, all of my animations get stuck on the first frame using this. I have tried everything, and I cannot fix it. Yes though, its using correct animation names and using the correct animations, it just won't ACTUALLY play them. This is VERY close to being a home run asset for me, and I would love some help :)
     
  25. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844

    Well, if you tried everything and did everything right its hard for me to tell you what could have gone wrong :D
    My best advice would be to check the demo animations and see how they work. Should also work as a proof of concept that the product works.

    Did you set the animations to humanoid?
     
  26. MichaelHF15

    MichaelHF15

    Joined:
    Mar 25, 2014
    Posts:
    50
    If I set the animations to humanoid the character flies up and down every frame in a very obnoxious way. Generic works best, as it does not do that, it loads first frame, AND... With your script, generic works. However, still only one frame, want to take a look at some of my code?

    $18e0e36a27ba223edfe6ac7580c7791a.png
    $3b6905f7e113094e1de735b3cbf55587.png

    That's essentially what I have been using for all of it.
     
    Last edited: May 22, 2014
  27. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    If you are working with humanoid characters you shouldn't use generic animations. Humanoid animations is one of the main reasons to use Mecanim. Here is a quick explanation on the generic animation: http://docs.unity3d.com/Documentation/Manual/GenericAnimations.html

    You need to adjust your humanoid animations in order to make them work. When you convert to Humanoid, make sure you go to the animation tab and play around with the options for rotations and root pose. This is a pretty essential step when using Humanoid animations with Mecanim in general (regardless of using Mecanim Control or just the Animator component provided by Unity). All Mecanim Control is doing is letting you use a few lines of code instead of depending on their state machine system. Here are some other useful links:

    Avatar Setup and Humanoid animation:
    http://docs.unity3d.com/Documentation/Manual/AvatarCreationandSetup.html

    Humanoid Animation options:
    http://docs.unity3d.com/Documentation/Components/class-AnimationClip.html
     
    Justice0Juic3 likes this.
  28. MichaelHF15

    MichaelHF15

    Joined:
    Mar 25, 2014
    Posts:
    50
    Actually really helpful, got it to work, perfect! Thanks, great work :D
     
  29. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    I picked this up thinking I'd be able to change the animation in a given state at runtime. Instead, it seems I need to use this INSTEAD of the state machines, replacing them completely, with no middle ground.

    Is this correct? I can't use mecanim state machines and change an animation at runtime? Kinda makes this purchase useless for me...
     
  30. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    It seems I can now use AnimatorOverrideController to do what I want - it wasn't available the last I looked into this.
     
  31. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    with your system would I be able to access the blend variable with a mouse scroll wheel?

    Example, I have two procedural motions that change slightly and I want to change one from the other with my scroll wheel of my mouse... would I be able to accomplish this?
     
  32. ruth-salguero

    ruth-salguero

    Joined:
    Feb 26, 2014
    Posts:
    6
    Hello MMind,
    really nice work!!!

    I'm new in Unity/animation and I'm evaluating your asset to buy.
    What I need is to "mix" animations... for example:
    I have a humanoid character... and I want "mix" the WALK animation with a FACIAL animation, while walking. So simple.
    It's possible with you asset? How?

    Could you or anybody here could help me please?

    Thanks in advance.

    Ruth.
     
  33. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    I bought your asset today when I ran into issues with Builds failing because my scripts were referencing the
    "UnityEditorInternal" namespace.

    It's truly great. Thank you so much!

    I think I found a small bug in the MecanimControl.cs script for version 1.0.4:

    In the Awake() method, if defaultAnimaiton.clip != null (i.e., I've explicitly set a default clip),
    SetDefaultClip() does not get called and currentAnimationData does not get initialized.

    This causes the OnGUI() method to fail when it tries to get the currentAnimationData.clipName because currentAnimationData is null.

    I've added the following else condition to the if statement in the Awake() method, which initializes the currentAnimationData object and starts the default animation:

    Code (CSharp):
    1.         else
    2.         {
    3.             currentAnimationData = defaultAnimation;          
    4.             Play(defaultAnimation.clip, 0, 0, currentMirror);
    5.         }
    Unless I've set something up incorrectly and the above code is unnecessary, please consider adding it (or something similar) to the next version of your asset.

    I have a question: Is there a way to automatically import my model's animation setup to the "animations" array of the MecanimControl component or do I have to do this in code at runtime?
     
  34. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Hey....auhhh... MMind... anybody there...there...there... hello...hello...hello... echo...echo...echo...

    Last post in May... Now July, just sayn...
     
  35. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852

    Having worked with this asset for several hours today and since I feel like I owe MM much more than $10 for this amazing asset, I guess I can answer your question from last month.

    First of all, you can do what you are asking in mecanim already. Here's a tutorial I found to show how to transition between animation states based on a parameter: link. I found it via Google. If you don't like this one, just do a search and I'm sure you will find many others that cover this issue

    And here's an example of processing scroll wheel input: link.

    This asset is meant for much more complex scenarios with dozens of animations and complicated logic for when to transition between states.

    That said, you can easily use this asset to process the scroll wheel and manually call CrossFade to switch between your animations.

    Note that posts earlier in this thread talk about how CrossFade is not quite as nice as configuring a traditional mecanim controller state transition because you don't get control of how the two animations overlap.

    A common mecanim feature demo (you can probably find it in the Unite video archives) is to show an example where a default transition can look wrong because the legs end up crossing through each other as the two animations overlap (this won't always happen; they contrived it for the demo). They then show how easy it is to visually configure the transition to change the overlap point, which prevents the legs from crossing. It's actually pretty awesome.

    Because the mecanim APIs are not fully exposed, we can't do the above transition manipulation in code. It can only be done using stock mecanim. There are other important mecanim features like blended animations that cannot be done in code yet for the same reason.

    Future versions of Unity/mecanim will hopefully expose more of the APIs so we will be able to accomplish more in code.

    The point is that there are trade offs both ways and you need to figure out which approach is best for what you are trying to accomplish.

    I would implement your example using stock mecanim.

    But if you have many animations with lots of branching logic based on input and game state to determine your transitions, then this asset is, in my opinion, the only way to go.

    I hope this answers your question.
     
  36. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Thanks schmosef for taking the time to answer my question and for providing links for more information, I really appreciate your help.
     
  37. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Sorry about this Licarell. I was not receiving e-mail warnings about this post so I just assumed there were no new messages. I think it was due to this new forum update. I'm truly sorry about this.
    A big thanks to @schmosef for answering this question.

    Thank you so much for that. This fix will undoubtedly help people with similar questions =)
    I actually have some slight improvements to the tool after Unity 4.5 that fixes a few minor issues, however I believe that with Unity 4.6 we will finally see some revision on Mecanim that will allow us to freely use Mecanim Control 2.0, which will once and for all fix all blending issues the tool currently has.
     
    Last edited: Jul 24, 2014
  38. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Awesome work on this asset.

    "I believe that with Unity 4.6 we will finally see some revision on Mecanim that will allow us to freely use Mecanim Control 2.0"

    Do you mean that MC2.0 will be able to use all of the Hidden libraries and able to build the project?

    Edit: forgot to ask: Does the current version of MC capable of modifying individual animation speed within an animator separately?
     
  39. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    That is correct. That is what I hope they do.

    Yes, the controls work like an emulated animation (legacy) component.
     
  40. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    It looks like the beta for 4.6 is available. When you get a chance, please confirm your prediction regarding our ability to freely use Mecanim Control 2.0. I'm hoping we won't have to wait for Unity 5.0 for this to work.
     
    Last edited: Aug 20, 2014
    hopeful likes this.
  41. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Any chance of CrossFadeQueued?
     
  42. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Sorry, apparently no significant changes have been done on 4.6.
    I remember reading a blog post in which they spoke of additions to Mecanim on Unity 5, so I guess we will just have to wait.

    I'll look into it.
     
  43. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Thanks for checking into this for us.
     
  44. lloydhooson

    lloydhooson

    Joined:
    Apr 7, 2008
    Posts:
    77
    Hi, can this be used with Unity 4.5/4.6 version of unity for IOS and Android build platforms for building to stores?

    Thanks.
     
  45. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    There shouldn't be any problems when it comes to export. In fact UFE already uses this technology to provide mobile support as seen here:
     
  46. Skullbot

    Skullbot

    Joined:
    Jul 12, 2014
    Posts:
    15
    Amazing asset. Makes things way easier than working with Mecanim when using simple animations.

    Is there any way to fire events, like footsteps ? I tried something but it's unreliable as it's not fired everytime (depending on framerate).

    Code (CSharp):
    1. void Footsteps()
    2. {
    3.    if( mecanimControl.GetCurrentClipName() == "run" )
    4.    {
    5.      // Left foot grounded
    6.      if( Mathf.Round( mecanimControl.GetCurrentClipPosition() * 100 ) == 40 )
    7.        audio.Play();
    8.      // Right foot grounded
    9.      else if( Mathf.Round( mecanimControl.GetCurrentClipPosition() * 100 ) == 90 )
    10.        audio.Play();
    11.    }
    12. }
    Maybe with a basic implementation of user-parameter-defined event ? (Here, when the animation reach a defined progress %)
     
  47. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    Hey there,
    Yeah, depending where you fire this, that will happen. This is because the animation run on its own threat, meaning the percentage you get may change every so slightly every time you try to catch the value.

    Try using that same code on FixedUpdate, and instead of detecting absolute values, try making an approximation or a toggle to when the value is passed. Like so:

    Code (CSharp):
    1.  
    2. bool step1 = false;
    3. bool step2 = false;
    4. void Footsteps()
    5. {
    6.    if( mecanimControl.GetCurrentClipName() == "run" )
    7.    {
    8.      // Left foot grounded
    9.      if(!step1
    10.         && Mathf.Round( mecanimControl.GetCurrentClipPosition() * 100 ) >= 40
    11.         && Mathf.Round( mecanimControl.GetCurrentClipPosition() * 100 ) < 90 ){
    12.               audio.Play();
    13.               step1=true;
    14.               step2=false;
    15.        }
    16.  
    17.      // Right foot grounded
    18.      else if(!step2 && Mathf.Round( mecanimControl.GetCurrentClipPosition() * 100 ) >= 90 ){
    19.               audio.Play();
    20.               step1=false;
    21.               step2=true;
    22.  
    23.        }
    24.    }
    25. }
     
  48. Skullbot

    Skullbot

    Joined:
    Jul 12, 2014
    Posts:
    15
    Yeah, I see what you mean.
    Footsteps() is already called inside FixedUpdate though.
    I'll try this, thanks ;)

    Any change on getting callbacks/events on this within your asset in the future BTW ?
     
  49. Mistermind

    Mistermind

    Joined:
    Jun 8, 2013
    Posts:
    844
    MC already have a few events as described here:
    http://www.ufe3d.com/doku.php/mecanimcontrol#public_events


    Through Mecanim Control currently there are no events that can handle an exact frame by frame animation progress (as they run on separated update threads), however I've seen some work around many times related to events on Mecanim. Seems to be a relatively common question on Unity Answers:
    http://answers.unity3d.com/questions/615041/mecanim-animation-events-1.html


    In other news,
    I recently been on a conference where the guys behind Mecanim showed some of the new features that will be available on Unity 5, and that included a wider control of animation calls and state machine, as well as exposing the hidden libraries currently being used by Mecanim Control 2.0 (available on a zip file inside MC package). As soon as Unity 5 is publically available I'll fully review Mecanim Control.
     
    hopeful likes this.
  50. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    in Unity5, i replaced the script you asked but:

    Assets/MecanimControl/Scripts/MecanimControl.cs(15,38): error CS0234: The type or namespace name `State' does not exist in the namespace `UnityEditorInternal'. Are you missing an assembly reference?

    if invoice needed i can send please help me .

    Many thanks ! this plugin is really great !