# NavQueryBuffer

> A buffer that stores intermediate node data during NavMesh pathfinding operations in a NavWorld.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.AI.Navigation.LowLevel](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** UnityEngine.AIModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [IEquatable\<NavQueryBuffer>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct NavQueryBuffer : IDisposable, IEquatable<NavQueryBuffer>
```

## Remarks

A NavQueryBuffer is required to use the pathfinding methods of [NavWorld](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld.md). To obtain a path between two locations on the NavMesh, create a NavQueryBuffer with a `maxNodesToVisit` value in the range from 1 to 65,535, then call the following [NavWorld](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld.md) methods in this order: `BeginFindPath`, `ContinueFindPath` (can be repeated), `EndFindPath`, `GetResultFromFindPath`. These methods store their intermediate state in the NavQueryBuffer.

NavWorld pathfinding operations that use a NavQueryBuffer can be executed inside jobs ([IJob](/engine/6000.5/script-reference/unity/jobs/ijob.md), [IJobFor](/engine/6000.5/script-reference/unity/jobs/ijobfor.md)), as opposed to the operations in the [NavMesh](/engine/6000.5/script-reference/unityengine/ai/navmesh.md)-related structures.

Copying this object produces only a new reference to the same underlying buffer. It doesn't duplicate the buffer in memory.

All methods throw exceptions if any of their data isn't valid when executed in the Editor.

## Examples

```csharp
using Unity.Collections;
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class NavQueryBufferExample : MonoBehaviour
{
    NavWorld m_World;
    NavQueryBuffer m_Buffer;

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();
        // Allocate a persistent buffer sized for the longest expected path.
        m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 1024);
    }

    void Update()
    {
        NavLocation start = m_World.MapLocation(transform.position, Vector3.one, 0);
        NavLocation end = m_World.MapLocation(transform.position + transform.forward * 10f, Vector3.one, 0);
        if (!m_World.IsValid(start) || !m_World.IsValid(end))
            return;

        // The buffer carries the pathfinding state across the Begin/Continue/End calls.
        NavQueryStatus status = m_World.BeginFindPath(m_Buffer, start, end);
        while ((status & NavQueryStatus.InProgress) != 0)
            status = m_World.ContinueFindPath(m_Buffer, 64, out int _);
        m_World.EndFindPath(m_Buffer, out int _);
    }

    void OnDisable()
    {
        m_Buffer.Dispose();
        m_World.Dispose();
    }
}
```

## Constructors

| Constructor                                                                                                                                                                           | Description                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [NavQueryBuffer(Unity.AI.Navigation.LowLevel.NavWorld,Unity.Collections.Allocator,System.Int32)](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/ctor.md) | Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations. |

## Methods

| Method                                                                                                    | Description                                                                               |
| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [Dispose](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/dispose.md)         | Destroys the NavQueryBuffer and deallocates all memory used by it.                        |
| [Equals](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/equals.md)           | Checks whether two NavQueryBuffer values refer to the same underlying pathfinding buffer. |
| [GetHashCode](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/gethashcode.md) | Computes a hash code for identifying this NavQueryBuffer in hash-based collections.       |

## Operators

| Operator                                                                                                    | Description                                                                                 |
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| [operator ==](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/op-equality.md)   | Checks whether two NavQueryBuffer values refer to the same underlying pathfinding buffer.   |
| [operator !=](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/op-inequality.md) | Checks whether two NavQueryBuffer values refer to different underlying pathfinding buffers. |
