# Handle animation

## Creating the Animator controller

To add a custom animator controller first create one.

![](/files/-MA7rwv27gYrKn7UIEpY)

Next, design the animation node based graph as you want.

![](/files/-MA7sXgUHY_FDooBUrO6)

## Assigning a runtime controller

There are three possible approaches:

1. You can assign one big runtime controller to the Animator component directly and ignore individual controllers (states).&#x20;
2. You can use individual runtime controllers from each state. For more information please read [this](/ccp/fundamentals/implementation/character-state-controller.md#animation).
3. You can use a mix between 1 and 2.

## Using the Animator component

Any state can access the Animator component by using the "Animator" public property from CharacterActor.

```csharp
Animator animator = CharacterActor.Animator;
```

Once you got this reference you can do whatever you want. Here is a code snippet taken from the NormalMovement state (Demo):

```csharp
public override void PostUpdateBehaviour(float dt)
{       
    if (!CharacterActor.IsAnimatorValid())
        return;
    
    CharacterActor.Animator.SetBool(groundedParameter , CharacterActor.IsGrounded);
    CharacterActor.Animator.SetBool(stableParameter , CharacterActor.IsStable);
    CharacterActor.Animator.SetFloat(verticalSpeedParameter , CharacterActor.LocalVelocity.y);
    CharacterActor.Animator.SetFloat(planarSpeedParameter , CharacterActor.PlanarVelocity.magnitude);
    CharacterActor.Animator.SetFloat(horizontalAxisParameter , CharacterActions.movement.value.x);
    CharacterActor.Animator.SetFloat(verticalAxisParameter , CharacterActions.movement.value.y);	
    CharacterActor.Animator.SetBool(isCrouchedParameter , isCrouched);        
    
}
```

{% hint style="info" %}
It is recommended to set certain parameters during the `PreCharacterSimulation` and/or `PostCharacterSimulation` methods.

The reason for this is because the actor might modify the body velocity along the way, so the values won't be updated by the time the frame is rendered.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lightbug14.gitbook.io/ccp/how-to.../implementation/states/add-animation-to-a-state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
