Unity allows editing the animations to some extent after they're imported. It can save a lot of work and greatly speed up your workflow.
Before we start, you should prepare and import a Humanoid
rig with at least one animation. You can also use the provided example Unity project and go to the Chapter 01 Working with animations\Recipe 07 Looping mirroring and offsetting animations
directory. There is a scene called Example.file
there. In the scene Hierarchy
, you can find a Mirror
game object. It has an attached Animator Controller
in which you can find two animations: Wave
and WaveMirror
. In the Rigs
directory, you will find the Mirror.fbx
asset. If you select it and go to the Inspector
, and to the Animations
tab, you can find normal and mirrored animation examples, as well as looped animation examples (Idle
and IdleMirror
).
To set an animation to loop, you need to go through the following steps:
- Select the animated asset and go to the
Animations
tab. - Check the
Loop Time
checkbox and click on theApply
button. The animation is looped. - If your animation's first and last frames don't match perfectly, you can force them to match with the
Loop Pose
checkbox. It is not recommended to use this option for animations that have matching first and last frames.
To offset an animation, you need to go through the following steps:
- Select the animated asset and go to the
Animations
tab. - Select your animation and make it loop (
Loop Time
checkbox). - Enter a value in the
Cycle Offset
field, below theLoop Pose
checkbox. - Click on the
Apply
button.
To mirror an animation, you need to go through the following steps:
- Select the animated
Humanoid
asset and go to theAnimations
tab. - Find the
Mirror
checkbox on the bottom of the animation settings. - Check the
Mirror
checkbox and click on theApply
button. The animation is mirrored. - Mirroring animations works only for
Humanoid
rigs.
- Looping animations: This is a common technique used for all cyclic movements (walk and run cycles, idle animations, and so on). If you don't set an animation to loop, it will play once and freeze on the last frame.
- Offsetting animations: Sometimes it is convenient to offset the cycle of a looped animation. It is often used with the
Mirror
option for steering animations (clips used to turn the character while moving). We will be showing that in the Using root motion to steer a character recipe in Chapter 4, Character Movement. - Mirroring animations: This option works only with
Humanoid
rigs. It is used to flip the animation left to right and can save up to 50 percent of steering animations when combined with theOffset Cycle
option.
You can also mirror and offset animation states in the Animator Controller
. If you select an animation state and go to the Inspector
tab, you can find the Mirror
and Cycle Offset
options. There is also an option to use Animator Controller
parameters to switch the Mirror
option on and off and set the Cycle Offset
. You need to have a Boolean parameter defined for the Mirror
option and a float parameter for the Cycle Offset
. Those settings will be automatically synchronized with the parameters. Whenever you change a parameter value, the setting will also be changed.