# Animator Profiles

## Legacy system

In previous versions of the **FPS Animation Framework**, we had a fixed amount of animation layers, specified directly in the **FPSAnimator** component:

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FRG8I0iRH8lTiZw99SIEK%2Fimage.png?alt=media&#x26;token=75f3346a-a6a9-4160-b098-d4ecfe1cf422" alt="" width="407"><figcaption><p>Legacy system.</p></figcaption></figure>

The problem with this design is obvious - scalability. What if we want to add an unarmed state? Or maybe swimming? What if we want a unique animation feature for this specific weapon?

The new **Scriptable Animation System** eliminates this problem by introducing a dynamic linking system for animation features.

## Dynamic Linking

This concept is incredibly simple - animation feature encapsulation. To achieve this, the new system relies on **Animator Profiles**:

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FF5vXZqjMh33zXt63GqMY%2Fimage.png?alt=media&#x26;token=0b260e23-b4e6-4f8c-a089-744311b47038" alt="" width="410"><figcaption><p>Profiles!</p></figcaption></figure>

An **Animator Profile** is a Scriptable Object, that contains procedural animation features (**FPSAnimatorLayerSettings**). There are no limitations on how to use a profile. Whether it is a weapon, item, or a climbing state - it is possible to add custom features required for a specific gameplay scenario.

{% hint style="success" %}
**Example:** imagine you want to add a ladder-climbing feature. You don't need Aiming or Recoil animation layers in this case. So you can create a new profile, which will include the features you need for this specific climbing state.
{% endhint %}

Here is how to link a new animator profile:

{% code title="FPSController.cs" %}

```csharp
private void EquipWeapon()
{
    ...
    _fpsAnimator.LinkAnimatorProfile(gun.gameObject);
    ...
}
```

{% endcode %}

In this example, we dynamically link an **Animator Profile** from the currently equipped weapon. For items and weapons, there's a special component called **FPS Animator Entity**:

<figure><img src="https://784345943-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxcUmJ78NSw1bSUlSO9oP%2Fuploads%2FNXSOxD5lCPuGUVueWW1F%2Fimage.png?alt=media&#x26;token=f1227f8b-2d6b-414a-a106-fdd82b2ae441" alt="" width="384"><figcaption><p>Entity can be a weapon or an item.</p></figcaption></figure>

This is just a data component, that contains an **Animator Profile** and a *Default Aim Point* transform (the [ads-layer](https://kinemation.gitbook.io/scriptable-animation-system/fundamentals/animator-layers/ads-layer "mention") uses it).

## Procedural Animation Features

A procedural animation feature consists of 2 entities:

* **Animation Layer Settings**: a Scriptable Object that contains feature data.
* **Animation Layer Job**: a struct that runs the procedural animation logic.

{% hint style="success" %}
**Tip**: separating data and execution entities makes the workflow more convenient. We can modify the data and see the runtime changes. It is also essential for Version Control since managing data assets is quite simple.
{% endhint %}

**Animation Layer Settings** asset is also responsible for instantiating a new **Animation Layer Job** when a new **Animator Profile** is linked. This is how it is handled in code:

{% code title="FPSBoneController.cs" %}

```csharp
protected void LinkAnimationLayers()
{
    foreach (var setting in _newProfile.settings)
    {
        var job = setting.CreateAnimationJob();
        if (job == null) continue;
                
        job.Initialize(_layerJobData, setting);
        job.UpdateEntity(_entity);
                
        var playable = job.CreatePlayable(_playablesController.playableGraph);
                
        _animationLayers.Add(new AnimationLayer()
        {
            job = job,
            playable = playable
        });
    }
}
```

{% endcode %}
