Mecanim Control

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 explaining how to use the 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 libraries from Unity that currently cannot be compiled into a build. Click here to read more about MC2 and Unity 5 update.

Easy to use UI
1495260--86349--$mecanim_UI.jpg

Control Mecanim like you control legacy!

As seen here:

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

Documentation: Mecanim Control [Universal Fighting Engine]

1495260--87874--$wiki:unity_as_badge.png
Price: Free

Any feedback is more then welcome!

cool.

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!

hi ! it’s look what’s i want ! and easy to do just use overrideController
i think’s concept is can be more flexible

Awesome. I’ll be releasing this week :wink:

nice don’t forget reply to my mail about fighting input :slight_smile: lol

http://www.ufe3d.com/doku.php/mecanimcontrol
Mecanim control documentation updated!

Mecanim Control released for just $10.00!

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

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.

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

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?

ok ill pick it up since its just $10 to play with, the benefits of making assets affordable :wink:

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

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…

here is a draft implementation of the events

		foreach(AnimationData animation in animations)
		{
			AnimationEvent animationEvent = new AnimationEvent();
			animationEvent.time = 0;
			animationEvent.functionName = "OnAnimationStart";
			animationEvent.objectReferenceParameter = animation.clip;
			animationEvent.messageOptions = SendMessageOptions.RequireReceiver;
			animation .clip.AddEvent(animationEvent);

			animationEvent = new AnimationEvent();
			animationEvent.time = animation .clip.length;
			animationEvent.functionName = "OnAnimationStop";
			animationEvent.objectReferenceParameter = animation .clip;
			animationEvent.messageOptions = SendMessageOptions.RequireReceiver;
			animation .clip.AddEvent(animationEvent);
		}

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 :wink:

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 :frowning:

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…

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)

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.

np thanks :slight_smile:

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?

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.