# NavMeshHit

> Information about a position that is the result of a query ran on the NavMesh.

## Definition

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

```csharp
public struct NavMeshHit
```

## Remarks

The object represents a valid result if the `distance` and `position` properties have finite values. Otherwise, the object represents a result that could not be calculated from the input data provided to the query. Refer to the documentation of each query method for details about the situations that produce invalid results.

**Note:** You can use `float.isFinite()` to determine whether a value is finite.

Additional Resources: [NavMesh.SamplePosition](/engine/6000.7/script-reference/unityengine/ai/navmesh/sampleposition.md), [NavMesh.FindClosestEdge](/engine/6000.7/script-reference/unityengine/ai/navmesh/findclosestedge.md), [NavMesh.Raycast](/engine/6000.7/script-reference/unityengine/ai/navmesh/raycast.md), [NavMeshAgent.FindClosestEdge](/engine/6000.7/script-reference/unityengine/ai/navmeshagent/findclosestedge.md), [NavMeshAgent.Raycast](/engine/6000.7/script-reference/unityengine/ai/navmeshagent/raycast.md), [NavMeshAgent.SamplePathPosition](/engine/6000.7/script-reference/unityengine/ai/navmeshagent/samplepathposition.md)

## Examples

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

public class ShowLineOfSightToTarget : MonoBehaviour
{
    public Transform target;
    NavMeshHit m_RayEnd;

    void Update()
    {
        // Detect whether a NavMesh edge blocks a straight path to the target.
        NavMesh.Raycast(transform.position, target.position, out m_RayEnd, NavMesh.AllAreas);
        var isRaySegmentOnNavMesh = float.IsFinite(m_RayEnd.distance);
        if (isRaySegmentOnNavMesh)
        {
            Debug.DrawLine(transform.position, m_RayEnd.position, m_RayEnd.hit ? Color.red : Color.green);
            Debug.DrawLine(m_RayEnd.position, target.position, Color.gray);
            if (m_RayEnd.hit)
            {
                Debug.DrawLine(m_RayEnd.position, m_RayEnd.position + Vector3.up, Color.red);
                Debug.DrawLine(m_RayEnd.position, m_RayEnd.position + m_RayEnd.normal, Color.yellow);
            }
        }
        else
        {
            Debug.DrawLine(transform.position, target.position, Color.magenta);
        }
    }
}
```

## Properties

| Property                                                                          | Description                                                       |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [distance](/engine/6000.7/script-reference/unityengine/ai/navmeshhit/distance.md) | Distance to the point of hit.                                     |
| [hit](/engine/6000.7/script-reference/unityengine/ai/navmeshhit/hit.md)           | Flag set when the query encounters a particular valid situation.  |
| [mask](/engine/6000.7/script-reference/unityengine/ai/navmeshhit/mask.md)         | Bitmask that specifies the NavMesh area type at the point of hit. |
| [normal](/engine/6000.7/script-reference/unityengine/ai/navmeshhit/normal.md)     | Normal of the polygon edge where the query terminates.            |
| [position](/engine/6000.7/script-reference/unityengine/ai/navmeshhit/position.md) | Position of hit.                                                  |
