Using Animator
Last updated
Last updated
Understanding the Animator component is crucial to navigating the Reactor process as this is what Reactor will take control of once an event is triggered.
Reactor can modify the parameters in the Animator component, which can trigger different animations. These are set up using the Node Graph in the Animator window.
A simple example would be an if statement. If the player walks into collider set the OpenDoor parameter to true, which will play the animation to open the door.
The Animator component is usually added automatically if you use the method discussed in the Animation docs found in the previous tutorial. It is possible to add it manually as well.
With the Animator component applied, you should be able to see the animations you have created in the Animator window. This is also called a Node graph.
If the Animator Window is not visible, you can go to Window Menu > Animation > Animator. Note how the animation nodes aren't visible until you click on the asset with the Animator component with animations applied.
If you haven't already, you need to create multiple animations to switch between. If you are animating within Unity, you can use the 'Create New Clip' in the Animation window.
The Animator Node graph is where you set up all your animations to control using the Reactor Component. With your animated asset selected, going to the Animator Window will give you something like the following :
To the right of the window you have the Node Graph itself. this houses all the animations you have created on the asset and a few other nodes.
The Orange node (with 'Cube_Idle' above) is the default state animation. This is the animation that plays when you start the Mona space. This could be an idle state, base state, or similar state that your asset will be in when the space loads. The name of this node is based on the animation file name initially.
The Grey nodes (in this case with 'Cube_Move') are all the separate animations you have created with the Animation tool. The name of these nodes is based on the animation file name initially.
The Any State node allows us to switch to an animation from any other animation. If you have a more complicated node graph, this is useful to clean things up for organisation.
Entry/Exit nodes are less important apart from the entry node leading to the Default state node.
If you want to change which animation is the Default animation, right click the node and select 'Set as Layer Default state'.
To move nodes around the graph, just left click and drag as needed.
At the top left you have two buttons, Layers and Parameters.
Layers Tab - This is less important as it is used to allow you to layer animations over other animations. This is not usually used unless you have some advanced use of the animation tools.
Parameters Tab - This is used to create parameters that allow you to trigger switching between animations in the Animator window. You will need this tab to create Reactor events.
Parameters are where a lot of the power behind Reactor can be.
A simple example would be to create a parameter that is used to note if a door is open or not. This is a great use of a true/false parameter, also called a Boolean. We can set this parameter using the Reactor component when an event happens, that way we can switch between animations.
Select the Parameters tab in order to add custom parameters
Add an example parameter that we can use
Pay very close attention to the spelling and case of the parameters you set as this will be important when adding them to your Reactor component later. Come up with a standard and stick to it to reduce issues.
To trigger an animation, we need to transition between them. And to do that we need to add a transition between the animations.
Right click on an animation and select 'Make Transition', then drag and select the animation you would like to transition to.
Once the transition is made, you can select the transition arrow in order to set how the transition is done in the Inspector window.
'Has Exit time' means the transition will happen at the end of the animation. Usually you will want the transition to happen as soon as the event is triggered, so this is usually turned off. That said you can use this to have an animation go to a different animation automatically (without needing Reactor to trigger it) or to transition to an animation after a certain point in the animation. Once turned off Unity will give you a warning saying there is no situation that the transition can happen, and this is where we add our Parameter condition.
Under the Conditions section, use the '+' sign to add a condition. This will add a parameter condition that we can reference with the Reactor Component. Select the parameter that you would like to reference. So basically If 'isDoorOpen' is true, play the 'Cube_Move' animation. And we can set 'isDoorOpen' to true when the player walks into a collider with Reactor.
Now that you have your animations created, your parameters set, and the transitions applied, you can move to the next tutorial in order to set up the Reactor component to trigger them!
There are some useful techniques that you could use to improve your Reactor experience however.
Things like doors, elevators, and platforms don't really require a looping animation to function. A door is either closed or open, and the animation is simply the transition between one to the other. Animator can do that animation for you, and you just have to focus on the end points as single keyframes such as the door closed, and the door open.
Doing it this way also allows you a little more control over how it transitions by modifying some of the values in the settings such as the transition length.
These can apply to position, rotation and scale. Even color, audio volume or other simple blends from one state to another.