# SetAreaCost(int, float)

> Sets the cost for finding path over geometry of the area type on all agents.

## Definition

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

```csharp
public static void SetAreaCost(int areaIndex, float cost)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the area to set.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): New cost.

### Remarks

This will replace any custom area costs on all agents, and set the default cost for new agents that are created after calling the function. The cost must be larger than 1.0.

Use [NavMesh.GetAreaFromName](/engine/6000.5/script-reference/unityengine/ai/navmesh/getareafromname.md) to find the area index based on the name of the NavMesh area type.

Additional Resources: Areas and Costs

### Examples

```csharp
using UnityEngine;
using UnityEngine.AI;

public class ToggleWaterCost : MonoBehaviour
{
    void Update()
    {
        if (Input.anyKeyDown)
        {
            // Make the water area 10x more costly to traverse.
            NavMesh.SetAreaCost(NavMesh.GetAreaFromName("water"), 10.0f);
        }
    }
}
```
