# GetLayerIndex(string)

> Returns the index of the animation layer with the given name.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AnimationModule

```csharp
public int GetLayerIndex(string layerName)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the animation layer to seek.

### Returns

| Type                                                       | Description                                                                  |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index of the specified layer. Returns -1 if the layer name is not found. |

### Remarks

You can use [Animator.GetLayerName](/engine/6000.6/script-reference/unityengine/animator/getlayername.md) to retrieve the name of an animation layer using its index.

```csharp
using UnityEngine;

// This example demonstrates how to use the Animator.GetLayerIndex method to get the index of a layer by name and then
// use it to set the weight of the layer.
[RequireComponent(typeof(Animator))]
public class GetLayerIndexExample : MonoBehaviour
{
    public string layerName = "Injured";
    public float weightDelta = 0.1f;

    private Animator m_Animator;
    private int m_LayerIndex;

    void Start()
    {
        m_Animator = GetComponent<Animator>();

        // Get the index of the layer by name
        m_LayerIndex = m_Animator.GetLayerIndex(layerName);

        if (m_LayerIndex == -1)
        {
            Debug.LogWarning("Layer not found: " + layerName);
        }
    }

    void Update()
    {
        if (m_LayerIndex == -1)
        {
            return;
        }

        // Increase the weight of the layer when the Up arrow key is pressed
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            var currentWeight = m_Animator.GetLayerWeight(m_LayerIndex);
            m_Animator.SetLayerWeight(m_LayerIndex, currentWeight + weightDelta);
        }
    }
}
```

Additional Resources: [AnimationLayers](/engine/6000.6/manual/animation-section/animation-mecanim/animation-animator-controller/animation-state-machines/animation-layers.md) manual.
