# FindClosestEdge(out NavMeshHit)

> Locate the closest NavMesh edge.

## Definition

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

## FindClosestEdge(NavMeshHit)

```csharp
public bool FindClosestEdge(out NavMeshHit hit)
```

### Parameters

**** (\[NavMeshHit]\(/engine/6000.5/script-reference/unityengine/ai/navmeshhit)): Holds the properties of the resulting location.

### Returns

| Type                                                          | Description                      |
| ------------------------------------------------------------- | -------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if a nearest edge is found. |

### Remarks

The returned [NavMeshHit](/engine/6000.5/script-reference/unityengine/ai/navmeshhit.md) object contains the position and details of the nearest point on the nearest edge of the Navmesh. Since an edge typically corresponds to a wall or other large object, this could be used to make a character take cover as close to the wall as possible.

### Examples

```csharp
using UnityEngine;
using UnityEngine.AI;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    private NavMeshAgent agent;
    void Start() {
        agent = GetComponent<NavMeshAgent>();
    }

    void Update() {
        if (Input.GetMouseButtonDown(0))
            TakeCover();
    }

    void TakeCover() {
        NavMeshHit hit;
        if (agent.FindClosestEdge(out hit))
            agent.SetDestination(hit.position);
    }
}
```
