Location: Samples/02 Fine Control/02 Live Inspector
Recommended After: Basics
Learning Outcomes: in this sample you will learn:
How to manually control Animancer via the Inspector.
How various parts of the Inspector correspond to code.
![](live-inspector.png)
Summary
This sample is a tutorial which gives step by step instructions on how to do a few things manually using the AnimancerComponent
's Live Inspector instead of using scripts.
You can't manually set up runtime behaviour like this, but viewing and fiddling with the animation details can be very useful for debugging issues in the Unity Editor.
Overview
The code used in this sample isn't important, it's only there to display instructions and wait for the user to follow them before moving onto the next step.
The tutorial consists of 11 steps:
![](select-animancer.png)
1. Select Animancer Component
To start, enter Play Mode and select the AnimancerHumanoid in the Hierarchy window to show it in the Inspector.
2. Initialize Animancer Graph
Right Click on the header of the AnimancerComponent
in the Inspector and select the Initialize Graph
function from the context menu.
This can be done in code by calling animancerComponent.InitializeGraph();
, but that's generally not necessary because anything attempting to use the graph will automatically initialize it.
Note how the character is now in a hunched over pose with their legs under the ground. That's the default pose for a Humanoid Rig when it has no animations so let's add some.
3. Show 'Add Animation' Field
Animancer uses Unity's standard preview area at the bottom of the Inspector:
- Click on the header to show or hide it.
- Drag the header to resize it.
- Right Click on the header to pop it out as a floating tab which can be docked wherever you like.
- Closing that tab will return it to the bottom of the Inspector.
Right Click on the word States
and select the Display Options/Show 'Add Animation' Field
function from the context menu.
4. and 5. Add Idle and Walk Animations
Use the Add Animation
field now showing at the top of the preview area to select the Humanoid-Idle
animation then Humanoid-WalkForwards
.
This is basically the same as calling animancerComponent.Play(animation)
.
6. Play Idle Animation
Ctrl + Left Click on the Humanoid-Idle
animation to play it.
This is basically the same as calling animancerComponent.Play(animation, AnimancerGraph.DefaultFadeDuration)
(which defaults to 0.25
).
7. Play Walk Animation As Well
With the Humanoid-Idle
animation still playing, Left Click on the Humanoid-WalkForwards
animation to expand its details then click the Play button in that state's details.
Doing that in code would look like this:
AnimancerState state = animancerComponent.States.GetOrCreate(walkAnimation);
state.IsPlaying = true;
Note how the Inspector now shows both animations playing, but you can still only see the Humanoid-Idle
pose in the Game window. That's because interacting directly with the details of a state only affects those specific details and the Weight
of Humanoid-WalkForwards
is still 0.
Weight
determines how much the state affects the animation output.IsPlaying
determines whether the state'sTime
is advancing (according to itsSpeed
).
8. Set Weight
Set the Weight
of Humanoid-WalkForwards
to 0.4
.
Now we have a blend of both animations playing at the same time. This sort of thing is normally achieved using Mixers, such as in the Linear Mixers sample.
Auto Normalize Weights
Note how setting the Weight
of Humanoid-WalkForwards
to 0.4
automatically changed the Weight
of Humanoid-Idle
to 0.6
so that they add up to a total of 1
. That's a feature of the Inspector which can be disabled via Display Options/Auto Normalize Weights
if you don't want it.
If you had set its Weight
in code like this:
AnimancerState state = animancerComponent.States.GetOrCreate(walkAnimation);
state.Weight = 0.4f;
Then it would only affect that state so everything can have whatever values you want.
9. Pause Graph
Click the Pause button at the top of the preview area to pause the character.
This can be done in code by calling animancerComponent.Graph.PauseGraph();
.
The character is now paused, but nothing else is. You can still Right Click in the Game window and drag to move the camera around.
10. Unpause Graph
Click the Play button at the top of the preview area to resume playing.
This can be done in code by calling animancerComponent.Graph.UnpauseGraph();
.
11. Set Speed
Click the 1.0x
button at the top of the preview area next to the Play/Pause button to show the Speed
slider.
Use that slider to set the speed to 0.5
.
This can be done in code by calling animancerComponent.Graph.Speed = 0.5f;
.
Conclusion
Watching the Inspector and using these controls to see how things affect the character can be very useful for debugging animation issues without needing to write new scripts just for that.