Mecanim Control

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

  1. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    $logo.jpg

    Mecanim Control is an open source coding tool made to allows developers to use a wider variety of methods with Mecanim (Humanoid/Generic) animations. It allows you to not only dynamically load any animation clip during runtime, but also tap into several methods currently missing in this magnificent system.

    As some of you know, currently, the Animator component and Runtime controller are still very limited due to its inaccessible code and visual dependent nature. Unfortunately Unity wasn't able to bring us many extra options after 4.3, but they did bring us just enough to have -some- control over it. After a few weeks of Mecanim implementation over my Universal Fighting Engine toolkit I managed to somewhat create an emulated version of the old Animation component. For the most part, it works like a charm.

    Features
    Mecanim Control currently support the following methods:
    - AddClip
    - CrossFade
    - GetAnimationData
    - GetCurrentAnimationData
    - GetCurrentClipName
    - GetCurrentClipPosition
    - GetMirror
    - GetSpeed
    - IsPlaying
    - Pause
    - Play
    - Remove Clip
    - Restore Speed
    - Rewind
    - SetCurrentClipPosition
    - SetDefaultClip
    - SetMirror
    - SetSpeed
    - SetWrapMode
    - Stop

    For more information on how to use all public methods and variables click here


    What is it for?
    This tool is useful for games running on Mecanim that requires more animations than the State Machine can handle. Although the visual editor is good when handling 5-10 animations, things can become a visual nightmare when you attempt to handle 20+ animations. Mecanim Control is the answer for that as it eliminates the need for the visual editor and gives the tools needed to code the animation inputs like you would in the old Legacy animation system.


    How it works?
    Based on a few words from Mecanim Dev that quickly mentioned how one could use AnimatorOverrideController , it was just a matter of creating a system that can do animation swapping and cross fading between 4 runtime animator controllers with 3 animation states each. Since its mostly references, there are no performance issues to speak of.


    Known Issues
    In order to apply a crossfade Mecanim Control needs to dynamically replace the animations being played on the State Machine at runtime. Because of that it resets the current animation to its first frame of animation which may cause small graphical glitches during blending.
    I've added an alternative approach to this issue in a zip file inside the Scripts folder called MecanimControl2.zip. Unfortunately it uses certain hidden libraries from Unity and those currently cannot be compiled into a build (waiting on Unity 5). If your project can wait for Unity 5, feel free to update the script. Mecanim Control 2.0 also doesn't require any external assets, meaning the script itself can be imported into any project with no dependencies.


    Easy to use UI
    $mecanim_UI.jpg

    [HR][/HR]

    Control Mecanim like you control legacy!
    $Mecanim_Script.jpg


    As seen here:




    If you can't wait for Unity to offer a more open source animator, Mecanim Control is perfect for you.

    Documentation: http://www.ufe3d.com/doku.php/mecanimcontrol

    $wiki:unity_as_badge.png
    Price: $ 10.00


    Any feedback is more then welcome!

    Last edited: May 7, 2014
  2. Play_Edu

    Play_Edu

    Member

    Joined:
    Jun 10, 2012
    Messages:
    513
  3. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    I haven't analyzed the possibility yet but it shouldn't be very hard to adapt it. I'll see what I can do. Thanks for the input!
  4. kilik128

    kilik128

    Member

    Joined:
    Jul 15, 2013
    Messages:
    288
    hi ! it's look what's i want ! and easy to do just use overrideController
    i think's concept is can be more flexible
  5. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Awesome. I'll be releasing this week ;)
  6. kilik128

    kilik128

    Member

    Joined:
    Jul 15, 2013
    Messages:
    288
    nice don't forget reply to my mail about fighting input :) lol
  7. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
  8. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
  9. MoHoe

    MoHoe

    Member

    Joined:
    Nov 5, 2012
    Messages:
    485
    Hey MMind!

    do you think this would help make a dual stick controller using mecanim?

    I'm looking for the same thing as Angrybots controls with dual stick functionality. But using mecanim system. I'm not fond of the angrybot method.

    If not, then do you feel confident that you could create such a controller? if yes then PM me how much you would charge.

    Regards
    Mohoe
  10. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    I'm not 100% sure if I understood your question. How would you use dual stick to control the character in that sense?

    But regardless, I don't know if Mecanim Control is exactly what you are looking for. Generally speaking this tool is useful for games that requires an avatar to run between a lot of animations or dynamically add or replace animations. The Animator Visual Tool is good for small situations like 5-10 animations, but when it comes to complex games that requires characters to have 30-50 animations the visual editor can get messy to a point of becoming unusable. Mecanim Control is the answer for that as it eliminates the need for the visual editor and gives the tools needed to code the animation inputs like you would in the old Legacy animation system.
  11. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    looks interesting is there a webplayer demo online we can try before buying

    also is there callbacks like when animation is complete? or is it just polling

    if not callback api would be nice to have like public void OnAnimationFinishedPlaying(animation) tha tgets called when the specified animation is completed
    Last edited: Feb 20, 2014
  12. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    there is a demo inside, but I don't know if I can actually prove the script's functionality in a web demo =D Any ideas?

    I didn't add event catching for the script, but that is a walk in a park really. I can add a few. Any other callback api suggestion?
    Last edited: Feb 20, 2014
  13. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    ok ill pick it up since its just $10 to play with, the benefits of making assets affordable ;)

    that one really when animation finished. but would be good to have one when animation starts

    OnAnimationStartedPlaying(animation)
    OnAnimationFinishedPlaying(animation)

    u can name it anyway u want, but its just so u can see what it does
  14. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    ok some more feedback

    isplaying always returns true for the current animation

    so can it return false when the animation has ended playing

    so in the example if im idle and i call isplaying with punch it should return false since obviously punch is not playing, then when i call play punch it should return true while it is playing but as soon as it is done with the punch it should return false, since punch is not looping. else it would have to return true. right now it continues to return true with punch since in our example its the last animation play was called with, but it should not be true since punch animation played and its done... so that sort of ties with the above. the above onanimationstart/onanimationstop (better names) for example should not be called cause i called play and its the animation, but when animation starts and stops so it has to tie into animation events to know or query the mecanim engine to see how animation is doing, better to use events i would think since polling (querying takes cpu cycles). can u do this with new mechanim api?

    also would be nice to know for looping animations how many times the loop ran since play was called and it started looping. so when play is called counter is set to 0 , then it would have to monitor each time the animation ran and increment counter and the api would return the counter and perhaps have clear counter api as well.

    also nice to have play api that would play n times for non looping animation and would use above counter so u can see each time it plays and how many remaining

    also would tie in to onanimationstart and onanimationstop so one could catch those two an dnot use counter

    i mean these r some ideas, i bet others can have their own, but those would be useful i think, and missing from mecanim or not like easy for non programmers..
    Last edited: Feb 20, 2014
  15. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    here is a draft implementation of the events

    Code (csharp):
    1.  
    2.         foreach(AnimationData animation in animations)
    3.         {
    4.             AnimationEvent animationEvent = new AnimationEvent();
    5.             animationEvent.time = 0;
    6.             animationEvent.functionName = "OnAnimationStart";
    7.             animationEvent.objectReferenceParameter = animation.clip;
    8.             animationEvent.messageOptions = SendMessageOptions.RequireReceiver;
    9.             animation .clip.AddEvent(animationEvent);
    10.  
    11.             animationEvent = new AnimationEvent();
    12.             animationEvent.time = animation .clip.length;
    13.             animationEvent.functionName = "OnAnimationStop";
    14.             animationEvent.objectReferenceParameter = animation .clip;
    15.             animationEvent.messageOptions = SendMessageOptions.RequireReceiver;
    16.             animation .clip.AddEvent(animationEvent);
    17.         }
    18.  
    im not sure they always firing, but its a start. im not expert in mecanim, but the idea is to have an event when it starts and when it ends. perhaps have count too as i posted so we can see how many times it plays, remember its not total times it plays its how many times it plays since play was last called on it so play will have to reset counter to 0 for the clip. i guess counter could be put in animation data. also i notice u like using some array but if many animations it maybe best to use dictionary so its quick to get from name, clip, ect to the one u want without looping through list...

    wow found bug already start being called twice each time!...

    ok did more testing start only repeat twice when play is called. so if animation loop u get

    start
    start
    stop
    start
    stop
    ...

    and if not loops

    start
    start
    stop

    when u call play

    i did more testing and its the call to

    SetCurrentClipPosition before the call to SetSpeed in _playAnimation causing the problem. i i comment out the call to SetCurrentClipPosition it does not fire. so... that will take a bit of tweaking... another night ;)

    commenting it out did not appear to break any of the animations and the events now fire correctly. the only thing i didnt check the call to CrossFade way which is when doing blending...

    basically a better way is to leave call to SetcurrentClipPosition and to make sure events dont get fired while its not playing. calling the event while play is being setup is not what we want so i wonder if there is way to enable/disable event or to perhaps set them in play just before animator.speed is set which is what really gets things going...

    and i also read on web that any time u set can be called multiple times or none at all. so it looks like events may have some issues, but ive not run into them so far..

    and obviously if u call play animation 2 while in the middle of playing animation 1 then is the onanimationstop fro animation 1 is not called :(

    so its going to take a little bit of playing around to get it to work just right, but it does not look too hard... just a bit of testing to find the cases where it runs into trouble...
    Last edited: Feb 20, 2014
  16. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    oh please add jump animation to demo scene

    preferably both

    jump in two animations making up jump (jump up animation and then come down animation)

    jump in one animation making up the jump (jump up and then come down animation)
  17. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    That is a lot to take in =D Hold on give me a few days and I'll provide you with a full answer and solution for everything you mentioned.
  18. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    np thanks :)
  19. Fuzzy_Slippers

    Fuzzy_Slippers

    Member

    Joined:
    Dec 21, 2012
    Messages:
    282
    I know your asset is focused on two characters at a time but any performance stats having dozens of characters running through your framework vs just plain mecanim state machines? Any of this feed the GC over time?
  20. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    It shouldn't be a problem. Mecanim Control creates instances for the animator controllers needed to operate on each character. Based on my tests here it didn't seem to be a problem in terms of performance.
  21. Fuzzy_Slippers

    Fuzzy_Slippers

    Member

    Joined:
    Dec 21, 2012
    Messages:
    282
    This is a very interesting asset. In an rpg context mecanim gets pretty messy as you need to have every possible equipment animation in your state machine somewhere. I've split it up into sub state machines and sync layers but alternatives would be welcome.
  22. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Just added those events. I'll have it explained in the documentations soon.

    I was reviewing the way I made this function and it definitely needs some rework. The problem has to do with Clamping the animation at the end. The animation component from unity has a similar problem, but as I can see here its easily fixable.

    That is a great idea! I'll definitely add it to the api.

    That is an amazing work =)
    I thought of a more general way that can be handled by your custom script using event subscriptions. Something like this:
    Code (csharp):
    1. void Awake () {
    2.     MecanimControl.OnAnimationStart += OnAnimationStart;
    3. }
    4.  
    5. void OnAnimationStart(AnimationData animation){
    6. ...
    7. }
    But the AnimationEvent system works just as well too. That is the beauty of programming right there =)



    I'm extremelly impressed by your work. See the biggest issue I had with Mecanim is that we can't control the wrapMode anymore, so I created an emulator that uses its own functions to control the clip. It also explains why we need 4 animation controllers =)
    I really feel MecanimControl is the kind of script that can be enhanced as time passes by. I revisited this about 3 times over the past month just to add an extra thing here and there.

    I'm not sure I should =)
    See, the animations I ported from Universal Fighting Engine were not created by me. They were authorized by their creators to be used in that package. I only managed to sneak a few here for demonstration purposes. I don't want to give them the idea that I might be trying to extend this particular package value. I hope you understand!
    Last edited: Feb 23, 2014
  23. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Version 1.0.2 sent to Unity!
    Change-Log:
    - Added 3 new animation events: OnAnimationBegin, OnAnimationEnd, OnAnimationLoop (Usage examples inside the demo folder)
    - IsPlaying Fixed
    - New function: GetCurrentClipPlayCount
    - Documentation Updated

    I'll let you guys know when the package is reviewed.
    Last edited: Feb 23, 2014
  24. MMM4

    MMM4

    New Member

    Joined:
    Feb 25, 2014
    Messages:
    1
    If I add a runtime clip using addClip, can I change a mecanim states animation to this new runtime added one?
  25. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    You won't have to worry about Mecanim States.
    This is how it works basically:
    On Unity 4.3 they added a new Class called "AnimatorOverrideController". It allows us to override the animator controller and with that, replace clips that were initially set in the State Machine.
    Functions like "Play" for example works by dynamically replacing the current playing clip with the ones stored in Mecanim Control by either using AddClip or using the UI.
    The configuration for the clips is very similar to those used in the Animation script (aka legacy animation).

    In essence, AddClip stores the animation inside the component, witch then can be called and played at runtime.
    Last edited: Feb 25, 2014
  26. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    thanks for the release!

    did some quick testing and working as expected!

    re: jump

    i dont need the animations for jump i have them

    what im really looking for is code example of how to handle 2 part animation like jump which has up and down :)

    could u talk me through how add the controller code and the demo code for like jump, and i can use my jump animations that i already have!

    thanks in advance!
    Last edited: Feb 26, 2014
  27. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Oh you mean the jumping system from UFE? That is in fact a very cool script =)
    That set of algorithms however requires the custom physics engine I made for UFE. It isn't related to Mecanim, but thanks to Mecanim Control I was able to port that functionality into Mecanim animations as well as Legacy.
    You actually just gave me some ideas. I could create other cheaper packages like this one for other features tapped on UFE.
    Custom physics with automated jump animation for example could be a thing, but I dunno if its enough to be considered a package. What you think?

    Sorry I can't give you a straight in-depth on how it works since its directly connected to the custom physics and the entire script is relatively big to post here.

    Edit: Just a small feedback on how it works - The custom physics allowed me to gather enough variables to calculate the distance, force and speed of the jump and fall. Then it was just a matter of applying some newtonian equations to make it so the jump animation starts at the bottom and ends at the top, regardless of the jump height.
    Last edited: Feb 27, 2014
  28. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    ur talking way past me and what i understand

    what i mean is that the standard legacy controller has jump so this controller needs a way to do jump. the problem ive seen is jump is actually 2 animations. 1st animation is going up and 2nd animation is actually falling down. so you have to have way to hit the jump key which triggers that 1st animation and moves the player up into air and then at some point switch to the 2nd animation and bring the player down to the ground. i guess the standard animation does this with some physics. i guess what im asking for is way to port standard legacy animation controller to use this asset so you get a replacement of standard legacy animation controller that uses mecanim animations instead of legacy animations and that uses this asset.

    perhaps have that as new affordable asset

    i mean i could try to port it.. i know c# its not that much code. every place they have their legacy animation i could switch to mecanim using this control, but i figured it would save me some time and others would want it too. it should not be too hard to even add to this asset it would bring the value up and even allow for price to go up or you could have it as an addon asset to this asset. so $10 for this and $10 for that makes $20 which is better than just $10... ;) but it would require the current animations, minus some that u dont need since its not part of standard controller, but it would need jump. and of course walk, run, crouch, ect...

    also standard ai controller that uses this asset and mechanim animations. i have a number of these but they are kudgy so say the least the problem being is that the authors that write them do not use events and such so they dont quite know when animation ended so they do a bit of tricks like have coroutine with sleep for fixed amount of time which results in less than ideal look and feel. it just looks strange how it plays out... also basically when u kick them off they go on until the timeout which is strange, the same for above controller so you ask for walk and until the walk timeout occurs you cant for example switch weapons. i wont shame any authors today, but u can imagine their assets really need this asset replacing their code...
    Last edited: Feb 27, 2014
  29. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    I know exactly what you mean.
    I remember playing a bit with that animation controller provided by Unity, but soon after I was already replacing my core files with custom controllers. Same for physics. There is a lot of potential in all the sub-assets used on UFE to become separated packages.
    As for a mecanim animation controller, that would be a really good bet for sure in terms of assets. What I could do is make a slightly more expensive controller asset that contains Mecanim Control. If you prefer however, I more than welcome you to create that sub-asset and make it so it requires Mecanim Control to function.
  30. im

    im

    Member

    Joined:
    Jan 17, 2013
    Messages:
    1,133
    re: "What I could do is make a slightly more expensive controller asset that contains Mecanim Control."

    sounds great. why not do that and put it on sale on unity. just basic animations as found in standard controller (dont forget my favorite jump)

    personally im more than busy doing other work. basically the game code unique to my game ;)
  31. Kreyg

    Kreyg

    Member

    Joined:
    Dec 31, 2012
    Messages:
    36
    This seems like everything I've always wanted from Mecanim, but Unity has failed to deliver on. I currently use legacy for a number of reasons, and one of them being the ability to control everything via code.

    Before I purchase this, I have to ask because I didn't see it anywhere in the documentation, but...

    CAN I set animation on different layers. The Mecanim tutorial Unity put out has the example where the player waves while idle, etc. I have a lot of animations set up like this with the legacy system. I was wondering if I will still have the ability to do so if I decide to use Mecanim Control.

    Thanks a bunch!
  32. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Hey there =)
    Humm unfortunately that was the one thing I had ignore completely while working this script :/
    However, now that you mentioned, I did some small research and there -might- be ways around it.
    Since the AnimatorOverrideController basically replaces the animation clips but retain the tree structure of the state machine its using, one could edit the attached controllers from the Resources folder and add a layer system using the visual editor itself.
    Its just a theory. I was just reading a bit here about layers and it seems they gave us just enough tools in terms of layer manipulation.
    As soon as I get some spare time here I'll definitely look into it. If you want you can give it a try yourself. Its full open source.
    Last edited: Mar 1, 2014
  33. msmsm

    msmsm

    Member

    Joined:
    Feb 1, 2014
    Messages:
    30
    Do you think it would be possible to add a sample() call to this? Now that you allow the time in a clip to be set being able to sample the bone transforms at this point would be very handy!
  34. SunnyChow

    SunnyChow

    Member

    Joined:
    Jun 6, 2013
    Messages:
    55
    it seems if i want to do a CrossFade() from AnimationClip A to AnimationClip B, both AnimationClip will play in frame 1.
  35. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Sure thing, but Sample() seems to be more of a combination of Play and SetCurrentClipPosition.
    Something like this:
    Code (csharp):
    1. mecanimControl.Play("walk");
    2. mecanimControl.SetCurrentClipPosition(.3f, true);
    Unless I'm understanding sample() incorrectly.

    You are 100% correct. There is in fact a bug with CrossFade. I pointed out in this thread under Known Issues and even posted a Unity Feedback here: http://feedback.unity3d.com/suggestions/animator-mecanim-crossfade-always-restarts-the-animation (make sure you vote it up so others can see it as well)

    I tried every possible work around with no luck. As soon as the crossfade is triggered, the first animation returns to the first frame. Its incredibly annoying :/
  36. msmsm

    msmsm

    Member

    Joined:
    Feb 1, 2014
    Messages:
    30
    I believe sample() applies the transformations to the bones immediately, rather than waiting for the animation section of the game loop (which, I believe, the play and set clip position will do). I am happy to be corrected if I have either of these wrong!
  37. SunnyChow

    SunnyChow

    Member

    Joined:
    Jun 6, 2013
    Messages:
    55
    Thanks
  38. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    This was originally posted as a reply to something else, but it might be extremelly useful for those looking for a CrossFade alternative solution:

    *This solution requires Mecanim Control and it has not been tested.*

    As we know, mecanimControl.CrossFade and mecanimControl.Play are just very enhanced methods to basically use the built-in animator.CrossFade and animator.Play. Problem is, this built-in CrossFade is basically defective.

    However, after some brainstorming earlier today, it might be technically possible to create an emulated crossfade using a blend tree and a float parameter that goes 0-1 emulating a "blending duration". Let me try to explain the best way I can:

    1 - Under each AnimatorControler (Resources\controller), replace all states with a blend tree.
    From this:
    $StateMachine.jpg
    To this:
    $BlendTree.jpg

    2 - Use the functionalities under the private function _play inside MecanimControl.cs to replace the clips inside the blending tree. Since OverrideAnimatorController works by basically replacing the clips inside the state machine without actually accessing it, it doesn't matter if the clip is under sub states or blend trees.

    3 - Create a new parameter that can be used to control the blend tree.

    4 - Now things get a bit complicated: Inside the _play method, replace the animator.CrossFade with an algorithm that sets the animator parameter to go from 0-1 by a speed factor serving as an emulated Blending Duration;The lower the speed, the higher the blending duration. This algorithm needs to be on FixedUpdate and triggered by _play.


    If anyone wants to try this approach let me know the results. As soon as I get some spare time I'll try that myself.
    Last edited: Mar 5, 2014
  39. Mcg

    Mcg

    New Member

    Joined:
    Mar 28, 2012
    Messages:
    61
    Bought this not long ago but not tried it out just yet but looks very useful mecanim trees causing me alot of repetitive work which looks to be solved by this, I saw someone mentioned it earlier but any update on play-maker support? :D
  40. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Hey there!
    No update on that yet. I haven't had the time to study PlayMaker.
    I'm currently still struggling to figure out a solution for the CrossFade issue, As soon as I have any news I'll post here. Make sure you subscribe to this thread ;)
  41. Kreyg

    Kreyg

    Member

    Joined:
    Dec 31, 2012
    Messages:
    36
    Just picked this up. Really looking to trying it out. Probably won't switch over to if fully, but it was a tool I wanted to add to my collection.

    Sadly I just read about the CrossFade issue! DAMN YOU UNITY! Who knows if they'll ever fix it. There are still issues from version 3.x and lower that never had a second thought paid to them.

    I love Unity, but their ideology of adding feature after feature and putting out tiny or no fixes at all for stuff really grinds my gears. They should take the entire 5.x cycle to not add anything new and fix everything.

    Fingers crossed they fix it.
  42. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    I think I just got really good news for you then =)

    after about 16 hours I managed to by pass the internal methods and made it work perfectly. Right now I'm just cleaning up the code and fixing some minor connection bugs to UFE, but expect an update with a FIX to that problem real soon ;)
  43. Kreyg

    Kreyg

    Member

    Joined:
    Dec 31, 2012
    Messages:
    36
    WOW, that's great news!

    I am going to be PMing you with a video very shortly.

    I am having a few issues at the moment getting it set up with my characters! HOWEVER, I think I will be switching to this provided I can get it to work properly!

    EDIT: Nevermind. I figured it all out :)!!!

    EDIT2: Still have 1 last issue. PMing you. Don't want to post it publicly.

    EDIT2: Solved it! Loving this tool!
    Last edited: Mar 10, 2014
  44. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Oh the approach I had to take to make the crossfade works is very different from the current MecanimControl. Its so different I'll probably provide the old copy in a zip file just as reference. Instead of replacing the clips at runtime, it automatically creates a StateMachine and add states and clips at startup. Then it just crossfades between the stored states with some algorithms to manipulate the component's speed (and not the states itself as it also causes the bug).
    The crossfade problem actually lied on the fact that any change to the animator controller component would reset it to the default state. In the case of MecanimControl, because it replaces the clips at runtime, the change itself would reset the first clip position.

    This was only possible due to the discovery of a hidden and undocumented class inside Unity's libraries. Most of the methods are probably untested and I had some issues with memory leaks, so its probably why they never got it "out to the public".
  45. Kreyg

    Kreyg

    Member

    Joined:
    Dec 31, 2012
    Messages:
    36
    Looking forward checking it out. I am absolutely loving this tool though. Thanks for making it!
  46. NightShade2109

    NightShade2109

    New Member

    Joined:
    Mar 5, 2013
    Messages:
    41
    Hey MMind


    Thanks for the great asset its working perfectly in my project.
    I never really like the visual editor for Mecanim but the advantage to Mecanim is the re-target-able characters with this you get the best of both worlds.

    Any there any plans to add layer functionality similar to the legacy system?
    I think that is the only thing missing from this tool then it would be able to replace the visual editor completely.
  47. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Hello there,
    I haven't sat down to analyze the possibility for layer functionality yet, but I do love the challenge. the next version of Mecanim Control has a completely different approach from the current version and that may give me an edge to apply the layers system. I'll keep you guys posted!
  48. NightShade2109

    NightShade2109

    New Member

    Joined:
    Mar 5, 2013
    Messages:
    41
    Awesome cant wait to see what you come up with next :)
  49. ddesmond

    ddesmond

    Member

    Joined:
    Feb 9, 2010
    Messages:
    141
    Hello,

    I just want to clarify that I can add / remove animations via code like the legacy animation system? For example, I can control at runtime, which animation to run?

    Thanks,
  50. MMind

    MMind

    Member

    Joined:
    Jun 8, 2013
    Messages:
    460
    Yes sir absolutely.
    The methods are fairly similar to the animation component:
    http://www.ufe3d.com/doku.php/mecanimcontrol

    Here is an example:
    Code (csharp):
    1. public class Example : MonoBehaviour {
    2.     public AnimationClip walkClip;
    3.     private MecanimControl mecanimControl;
    4.  
    5.     void Start () {
    6.         mecanimControl = gameObject.GetComponent<MecanimControl>();
    7.         mecanimControl.AddClip(walkClip, "walk");
    8.     }
    9. }
    Last edited: Mar 24, 2014