Shiny new animation features in Unity 5.0
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:
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.
(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…
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.
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.
Asset Creation API sample Code
// Creates the controller
var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath ("Assets/Mecanim/StateMachineTransitions.controller");
// Add parameters
// Add StateMachines
var rootStateMachine = controller.layers.stateMachine;
var stateMachineA = rootStateMachine.AddStateMachine(“smA”);
var stateMachineB = rootStateMachine.AddStateMachine(“smB”);
var stateMachineC = stateMachineB.AddStateMachine(“smC”);
// Add States
var stateA1 = stateMachineA.AddState(“stateA1″);
var stateB1 = stateMachineB.AddState(“stateB1″);
var stateB2 = stateMachineB.AddState(“stateB2″);
var stateC2 = stateMachineC.AddState(“stateC2″); // don’t add an entry transition, should entry to state by default
// Add Transitions
var exitTransition = stateA1.AddExitTransition();
exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransition.duration = 0;
var resetTransition = stateMachineA.AddAnyStateTransition(stateA1);
resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “Reset”);
resetTransition.duration = 0;
var transitionB1 = stateMachineB.AddEntryTransition(stateB1);
transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoB1″);
stateMachineC.defaultState = stateC2;
var exitTransitionC2 = stateC2.AddExitTransition();
exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransitionC2.duration = 0;
var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);
stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoC”);