# GetAreaFromName(string)

> Returns the area index for a named NavMesh area type.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.AI](/engine/6000.0/script-reference/unityengine/ai.md)
* **Assembly:** UnityEngine.AIModule

```csharp
public static int GetAreaFromName(string areaName)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the area to look up.

### Returns

| Type                                                       | Description                                                                            |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Index if the specified area name exists, or -1 if no area type has the specified name. |

### Remarks

```csharp
// NearestPointOnWater
using UnityEngine;
using UnityEngine.AI;

public class NearestPointOnWater : MonoBehaviour
{
    void Update()
    {
        // Find the nearest point on water.
        int waterMask = 1 << NavMesh.GetAreaFromName("water");
        NavMeshHit hit;
        if (NavMesh.SamplePosition(transform.position, out hit, 2.0f, waterMask))
        {
            Debug.DrawRay(hit.position, Vector3.up, Color.blue);
        }
    }
}
```

Additional Resources: [Areas and Costs](https://docs.unity3d.com/Packages/com.unity.ai.navigation@2.0/manual/AreasAndCosts.html) to learn how to use different Area types.
