Search Unity

The animation team has been working hard to pull together an impressive feature set for Unity 5.0. Here’s a quick overview of the new animation features you can look forward to!

State Machine Behaviours

In Unity 5, you’ll be able to add StateMachineBehaviour scripts to your states, and receive the following callbacks when the states are played:

  • OnStateEnter
  • OnStateUpdate
  • OnStateExit
  • OnStateMove
  • OnStateIK

You can have as many StateMachineBehaviours in your State as you like. So to add IK on State, or to do some custom logic, simply drag the StateMachineBehaviour script on to it.

Basically, anything that requires some kind of StateMachine logic in your game – with or without animation – can use this.

mecUnity5-1
Another great thing about this feature is that you don’t need to have tons of

(which I’m sure you have plenty of in your code),

you can just use StateMachineBehaviours instead!

State Machine Transitions

State Machines are growing more and more complex, so we introduced the concept of State Machine Transitions to provide a higher level of abstraction over the StateMachine logic.

In Unity 5, we’ve added Entry and Exit nodes to StateMachines. There are used during State Machine Transitions.

Entry:  When you transition to a StateMachine, the animation system will evaluate the Entry node and branch to the destination that its conditions meet.

Exit: When going to the Exit node, the animation system will look at the outgoing StateMachine transitions and branch to the proper destination.

Note that you can mix transitions: State->State, State->StateMachine, StateMachine->StateMachine…

mecUnity5-2

What’s more, we also revamped the UI for our tool so you can now re-order your parameters and layers.

Asset Creation API

In Unity 5 you can create animation assets; StateMachines, States, Controllers, Layers, Blentrees, etc., using scripts in the Editor!

There are two APIs, a high-level one, where the assets are managed by Unity and a low level one where you manage assets manually, and can perform external referencing.

Both APIs are documented, and I’ve put a small example of API usage at the end of this post.

Direct Blend Trees

We’ve added a new type of BlendTree that allows you to map an animator parameter to the weight of a BlendTree child directly.

mecUnity5-3

This can come in really handy if you’re working with BlendShape animations, or additive animations.

Root Motion Authoring (in generic mode)
Unity 5 also allows you to animate objects and convert their animator to root motion (ie Delta Animation). Simply create an animation – translation/rotation – on the topmost transform of an object then click Generate Root Motion Curve in the AnimationClip inspector!

More stuff that will make your life easier:

  • Improved animation previewer camera. The camera can now Pan, Orbit and Scale in the same way as the scene viewer.
  • Runtime access to parameters (name, default values etc..)
  • Gizmo in scene view for root position, ik position, etc…
  • Improved retargeting engine
  • Runtime optimizations
  • Tons and tons of bug fixes

Let us know what you think of these changes!

The Animation Team.

More about Unity 5.

 

Asset Creation API sample Code 

 

59 replies on “Shiny new animation features in Unity 5.0”

I read with interest the comments from MARGUEAUG because I feel exactly the same way.
Guys, before adding spiffy new features in Mecanim, please make the existing features work robustly.
I am also doing a mobile game and I am converting all of my Mecanim code back to Legacy. This is a lot of work for me, so I am not doing so lightly. You might think I am a noob programmer, but I am not. I was Lead Programmer at Ubisoft on one of the Prince of Persia title.

Here is a list of things that just dont work or break.

1) Animator not initialized error warning. If you set a game object inactive, you need to re-get the Animator component when making the object active again because often it will be lost. Why?
2) Some transitions (even from Any state) never get triggered and there is no message telling you why when the animator state machine clearly allows for that transition to happen. This seems like a bug. In the same vein, it would be nice to get a debug.warn when trying to go to a state not allowed in the your state machine to facilitate debugging.
3) If Unity crashes (and it does), the animation values can get corrupted. Unity as a whole recovers amazingly well from crashes except for mecanim. This means that animations that use to work, stop working on mobile (iOS) only (not in the editor though) with no error message. This is hell. I use to get an invalid layer index 0 in the previous version (4.4) (even though layer 0 was valid), now there is no message whatsoever. You need to delete all the animation controller and rebuilt from scratch to get it to work again (until the next crash).
4) When my hero dies (let’s say while sliding), I play a recovery animation. After the recovery animation SLIDE plays again for no known reason. Yes, I tried putting all the transitions to atomic and that did not change anything. It seems the animation state engine gets confused.
5) Mecanim is complex. A lot of us are not using Mocap. We are doing fun and straightforward casual games, not triple A titles. Please keep it accessible and fast.

To summarize, I feel Mecanim has a lot of potential, but is not robust enough for me to use without a lot of frustration and loss of time. If a Unity staff member has some thoughts regarding the points above (workarounds, if they will be addressed in the next version, etc) I would love to hear them.
Thank you

Looking at the API, while I see creating states, will we also be able to assign AnimationClips to those runtime created states? I hope so and if so, I want this yesterday :)

I hope that the animation logic made in Unity version 4.X will be automatically correctly converted when i upgrade project to Unity 5. If not i have to do a lot of work from scratch.

hi,
i hate the mecanim complicated,confusing and unnecessary ( «for me» is unnecessary ) workflow
not to mention I could not find examples of how to rotate/animate the character correctly with mouse look ( FPS ) and much less with thumbstick gamepad ( 360 degrees all the way / TPS adventure game), the only example I found was to just turn left and right.
the digital tutors course is ridiculous where you just can move foward and sideways and can not even rotate the character
and even if there were an example for each situation ( FPS / thumbstick 360 degress ) and I’m pretty sure does not have I really do not feel comfortable with mecanim and do not intend to use
I’ve seen many comments from a lot people who also hated
I never needed and will never need mecanim or other state machine similar thing to give life to my characters
I do not need anything more than the convicional ( Legacy )
and » if » one day I am unable to use Legacy for me is the end with unity!
I intend to launch a iOS Unity game with legacy ( just Legacy )
and I do not intend to and nor will update with mecanim later or in the future
and if this is a problem , let me know , that I did not continue the game with unity
I hope it never happens…

M­­­­o­­­­n­­­­­­e­­­­­­y­­­­­­­­ i­­­­­­­­s a­­­­­­­­­n­­­­­­­ e­­­­­­ss­­­­­­­­­­e­­­­­­nt­­­­­­­­­­­­ia­­­­­­­­l p­­­­­­­­­­­ar­­­­­­­­t o­­­­­­­­­­­­­­­­f ­­­­­­­­­o­­­­­­­­ur­­­­­­­­­­­­­­­ l­­­­­­­­­­if­­­­­­­­e,­­­­­­­w­­­­­­­­­­­­ith­­­­­­­­­­­out m­­­­­­­­­­­­o­­­­­­­­­­n­­­­­­­­­­ey­­­­­­­­­­­­ w­­­­­­­­­­e ­­­­­­­­­ar­­­­­­­­e­­­­­­­­­­­­­ no­­­­­­­­­­­­­th­­­­­­­­­­­in­­­­­­­­­­­g.Wh­­­­­­­­­­en ­­­­­­­­­­­­­i
l­­­­­­­­­­­­o­­­­­­­­­­­­­­­­­st ­m­­­­­­­­­­­y j­­­­­­­­o­­­­­­­­­­­­­­b i­­­­­­­­­­ w­­­­­­­­­­­a­­­­­­­s ­­­­­­­­ve­­­­­­­­r­­­­­­­y ­­­­­­­­d­­­­­­­e­­­­­­p­­­­­­­­r­­­­­­e­­­­­­s­­­­­­­­se­­­­­­­­­d t­­­­­­h­­­­­­­­en­­­­­­­­­ m­­­­­­­y ­­­­­­­­si­­­­­­­­­­s­­­­­­­­ter­­­­­­­­­­­ te­­­­­­­­l­­­­­­­­­l m­­­­­­­­­­­e a­­­­­­­­­bo­­­­­­­­­­­­­u­­­­­­­­­­­­t ­­­­­­­­­­­o­­­­­­­­­­­­­­n­l­i­ne ­j­ob­s­.­s­h­e­ t­e­l­l ­m­e t­h­­­­­­­­­­a­­­­­­­­­­­­t s­­­­­­­­­h­­­­­­­­­e
e­­­­­­­­­a­­­­­­­­­­r­­­­­­­­­n­­­­­­­­­s 1­­­­­­­­­1­­­­­­­­k ­­­­­­­­­­­a ­­­­­m­­­­o­­­­­n­­­­­­t­­­­­­h,­­­­­­­s­­­­­­o­­­­ i­­­­­­ t­­­­­e­­­­­l­­­­­­l ­­­­­­­­h­­­­­­e­­­­­­r t­­­­­­­­­­­h­­­­­­­a­­­­­t ­­­­­­i a­­­­­­­­­m ­­­­i­­­­­­n­­­­­­­­ter­­­­­­­­e­­s­t­e­d i­­­­n­­­­­­­ it a­­­­n­­­­d ­­­a­­­f­­­t­­­­­­e­­­r t­­­h­­a­­­t ­day i a­­­m e­­­a­r­­­n­­­i­­n­­­g 8­­­8$ p­­­­er h­­­o­­­­u­­r.Yo­­­­u c­­­­a­­­n a­­­­l­­­s­­o e­­­­a­­­r­­­­n­­,t­­­­­h­­­i­­s i­s w­­­h­­a­­t ­­­i ­­d­­­o­­..

=======>>> W­­W­­W.MoneyKin.C­­O­­M

It’s amazing that Unity will get a state machine that can be used outside of animations!
But, why have a «StateMachineBehaviour» base class whose OnStateUpdate methods include some animation parameters? shouldn’t it be called «AnimationStateMachineBehaviour»?

Don’t get me wrong, I know that you still have to create a «AnimationController» asset, and as such, the whole state machine thing is tightly packed with the animation stuff.

BUT, you advertised that the new state machine stuff can be used outside of animations, and PlayMaker (and others) did show, that this is a feature many will use.
In Unity 6 we might can create a pure «StateMachine» asset without the animation stuff, THAN you could introduce a «StateMachineBehaviour» class without worrying to break old code.
So wouldn’t it be more future prove to name the base class that gets all the animation parameters «AnimationStateMachineBehavior»?

I hope you will not remove the legecy animation system , i use it i never used mecanim and i wont use it forever .

@Gavalakis Vaggelis
Presumably because of performance reasons. Using MonoBehaviour directly would cause executing a lot of code and sending a vast number of events even if event notification is not used at all.
It’s just an assumption but I had the same consideration when I developed my open source asset AnimatorAccess which does pretty much the same for Unity 4.3

ZIBOO 26 Jun 2014, 6:00 pm
Is there a way to acces and modify curves of animations at runtime ?
It’s not possible right now… and thats a big shame, no way to make procedural animations from existing curves

PIERRE PAUL GIROUX 26 Jun 2014, 7:54 pm
@Ziboo: Not in 5.0 yet.

That’s really a shame. Can you explain why we can’t acces the animations curves of a clip and modify them at runtime ?
I’m not a software engineer but a lot of engines can do that..
And it’s really important for a project I’m working on.

@ALKIS

Oh I See :) Thanks :)

What about access/modify (correct/IK) bones after animation applied when «Optimize Game Objects» is checked?

@Jes

If you mean authoring the root motion for humanoids, rather than automatically calculate it from the body average position, that was added in 4.5. If not, sorry, I have misunderstood you! :-P

Cool stuff :)

May be I miss something, but will unity 5.0 mecanim have origin root motion from animation root? If not how can we achieve this?

Looking nice.

Question:
Why derive from that new StateMachineBehaviour and not get the callbacks on the existing MonoBehaviours of the Animator gameobject?
Unless I understood something wrong

Looking forward to this.
Will there be a way to bind animstate components to ranged frame markers that can be dragged by the editor user? I am hoping for a parallel to Unreal Notifies. Usage pattern example would be sweeping damage window of a melee attack animation.

One other question. Can other scripts get the state callbacks or just those behavior scripts on the states? Slightly worried about the number of components per object having scripts on every state will add.

Thanks,
-Matt

Frankly aside from the nice callbacks, I find nothing interesting because I just don’t need blending or even states for that matter cuz I can handle it myself in the logic like its supposed to be, What I can’t gandle is Free Form Deformation sprite renderers, constraints and IK creation and importing inside of unity, I need a simple 2D rigging system for Unity. If a fraction of Mecanim resources were dedicated to that we’d have it by now.
Believe me there is almost no proper 2D animation tool for Unity in the whole world, search if you want, but 60% of Unity’s 2D devs would love something concrete and vital that they can’t fix up themself.
How many of this blog reader would use all of Mecanim blendy sweetness vs How many would use FFD, Bones and Constraints/IK ?

Pretty cool features. I just finished yesterday my open source code generator (https://github.com/kayy/AnimatorAccess) that does pretty much the same: Events on states and transitions, access to state info,…

Well, it’s a pity on one hand as it will be obvious in a few months but on the other hand it’s always better to have these features out of the box.

Small request (this is the wrong place for it but what the hell)

Is there a way to control the Transition blend between states so that we’re not limited to simply «linear cross fade». I’d love to be able to have something an AnimCurve to define this, or just a smooth step/s curve!

i know its off topic but something i’ve been wanting to know about is unity 5’s level streaming. i understand if you cant comment on it but if you could that would be great.

1. does it work while in the editor?
2. can it be controlled through scripts
3. how much control will we have? (can i load based on world position, trigger areas, etc…)
4. can i load and unload assets or asset packs in a standalone game.

Tips: allow us to set up our own systems and also allow us to control it all through scripts.
a simple Streaming.LoadAssetBundle(«DungeonRoom2»); with some callbacks for stuff like streaming started streaming, finished streaming asset, finished streaming bundle. this way we could make a trigger that called this command or a more complex system. ALSO: please let us control asset bundles in the editor. Example: please make it so i can write an extension that puts my object into the appropriate asset bundle based on the position without my help. then i can also write one for loading and unloading the bundles based on editor camera position.

P.S. i’m not talking about web player i’m talking about actual level streaming, open world, etc…

@Pierre Paul: I don’t mind dealing with states instead of clips (after that’s what the legacy animation[«clip»] returns, an AnimationState), but doing «animator.Play(state, normalizedTime)» is not nearly as convenient, or consistent, as setting a parameter.
Plus, it is *Play*, not *go to*: last time I tried to use it the state kept trying to advance time on its own. I want it to stay stuck on my parameter.
This is for eg an additive leaning animation.

@MEPHISTO: http://docs.unity3d.com/ScriptReference/Animator-speed.html

@HOESTEREY: You can use AnimatorOverrideController for this – you make your state graph for the male animations, then create an AnimatorOverrideController asset in which you map each male animation to the corresponding female animation. You can use this to create multiple variants – different enemy types, etc.

Amazing changes,
What about swaping animations at runtime?
e.g male and female models use same state graph for logic and transitions but with different animations. Can I swap these animations in code or do I need to duplicate the entire state graph?

Is there anypoint asking questions here? I have one killer problem stopping me from using mecanim. How do you change animation speed for individual actors?

Thats definitely a major leap forward.
While some of it probably is only of interest to AAA complexity level content, the possibility of the script even without putting much thought into it seems insane to infinte.
Can’t wait to give them a go.

If I created a state with an ‘empty’ animation in – i.e. I created a new .anim file but didn’t put any curves in it – and set it to loop, then attached a StateMachineBehaviour to it, would I be able to do procedural animation in OnStateUpdate?

Or, for example: could I turn on all my physics components in OnStateEnter such that the character ragdolls, then turn them off again in OnStateExit?

Or is the way that default values get handled – as discussed in a previous blog post – going to interfere with that?

Looks good I could do a lot with this. Hopefully this also will come with the change to not reset animated values on state changes that would save me days of work when animating UI.

These are great and will help greatly to cleanup the code, especially checking IK states and reducing the IsState and IsTransition calls.

Updates to how parameters are managed are truly critical, they are unamanageable. Would be great to at least be able to segregate them by layer and/or substate machine

Specifying conditions that are checking for «equal» values via enumerator variables — or coming up with a way of defining an enumerated list for the state machine (but then being able to access it programmatically) would also be very helpful

Awesome, especially the StateScripts. Another important step towards an universal state machine system.

Is there any progress about changing time scales independently for different layers and even states? (I am especially thinking about the possibility to pause an layer by setting its time scale to 0)

Awesome updates guys, loved the new UI btw.
Question, are OnStatesIK and OnAnimatorIK a different stuff? or it will be replaced??
and how did it go with the ragdoll states? is it left out? looking for mecanim compatible active ragdoll stuff :D

@benblo, ideally connect anything mecanim to a parameter.
@PPG you need to speed up your plans to expose this API at runtime so we can do UGC brain.

PP! The internet elves are weeping! Please add a space to the CreateAnimatorControllerAtPath line so we can get a line break.

Also, great stuff ;)

Ah! I just ran into every problem you fixed no less than 5 days ago. Definitely exciting to see these improvements!

«Direct Blend Trees
We’ve added a new type of BlendTree that allows you to map an animator parameter to the weight of a BlendTree child directly.»
How about being able to control the TIME of a child directly via a parameter? I’m kinda stumped at how hard it is to do right now / impossible.
The old way: animation[«myClip»].normalizedTime = myParameter;

«Basically, anything that requires some kind of StateMachine logic in your game – with or without animation – can use this.»

Examples please. The code you have seems to rely on an animation controller but, you state that I don’t need to have an animation and can just use state machines for logic creation (I’m thinking playmaker style independent state machines).

Is there a way to acces and modify curves of animations at runtime ?
It’s not possible right now… and thats a big shame, no way to make procedural animations from existing curves

Pierre, could you tell us where the «logic» for the entry+exit nodes resides? For instance, can we use a script to tell the system ourselves which idle-animation it should play?

@Steven: Pierre Paul writes that «…you can create animation assets; StateMachines, States…»

Being able to add scripts to states is going to be a friggin’ game changer!.. Uh.. pun intended?

One thing that still bugs me when using Mechanim, which I do a lot, is that trigger and bool parameters look the same in the parameter list in the state machine. It’s pretty much impossible to know what time of parameter it is months after having created it.

I´ve wanted a direct blend tree for a while now , these changed cupled with the new Unet are starting to get me excited for unity 5

now if only we could get some way to blend ragdoll/script based bone movement with the animator that would be just great!

@USER13

We haven’t set the minimum requirements for Unity 5 yet, but our goal is to always make Unity as accessible as possible. That said the GMA 950 has very basic capabilities which may work with Unity and run the editor, but likely won’t be enough to run the new lighting and shading features of Unity 5 satisfactorily.

Very nice blog post. According to UI revamp – i wonder that moving parameter/layer to inspector space when nothing is selected in animator window (or alternatively – list always is on top no matter that something is selected or not) isnt better? this could save space in animator window for bigger graph practically without drawbacks (if we choose alternative version)

You mentioned that in unity5 we dont need use GetCurrentAnimatorStateInfo() method but didnt show example what we need write in unity5. Could you post small example template for idle state (without game logic)?

Can you please tell me what the System Requirements for Unity 5 wiil be?

I cant afford new System, i currently use a laptop with GMA 950. But i have a 32 bit p4 Desktop with AGP slot, so i think i will buy a AGP card somewhere, dont know if i will even find one though. So i am quite worried that Unity 5 will be too heavy for my system and i will be stuck with 4.5 .. :(

Thanks

Comments are closed.