# NavQueryBuffer(NavWorld, Allocator, int)

> Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations.

## Definition

* **Type:** Constructor
* **Namespace:** [Unity.AI.Navigation.LowLevel](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** UnityEngine.AIModule

```csharp
public NavQueryBuffer(NavWorld world, Allocator allocator, int maxNodesToVisit = 1024)
```

### Parameters

**** (\[NavWorld]\(/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld)): The [NavWorld](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navworld.md) for which this buffer is used. The buffer can be passed only to methods of the same NavWorld it was created with.**** (\[Allocator]\(/engine/6000.5/script-reference/unity/collections/allocator)): The label indicating the desired lifetime of the object. The `allocator` parameter has no effect; the buffer is always allocated as [Persistent](/engine/6000.5/script-reference/unity/collections/allocator/persistent.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The maximum number of nodes that can be stored in the buffer during a search operation. Unity clamps this value to the range from 1 to 65,535. The default value is 1024.

### Remarks

Use the `maxNodesToVisit` parameter to size the buffer for the pathfinding methods that use it, such as `NavWorld.BeginFindPath`, `NavWorld.ContinueFindPath`, `NavWorld.EndFindPath`, and `NavWorld.GetResultFromFindPath`. If the buffer is too small for the search, the pathfinding method returns a [NavQueryStatus.MaxNodesToVisitExceeded](/engine/6000.5/script-reference/unity/ai/navigation/lowlevel/navquerystatus/maxnodestovisitexceeded.md) status. Unity clamps `maxNodesToVisit` to the range from 1 to 65,535. A value outside that range doesn't prevent Unity from creating the buffer: Unity logs a warning in the Editor and allocates the nearest allowed size instead.

For more information about the container type that this buffer follows, refer to Introduction to NativeContainer.

### Examples

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

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

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();

        // The buffer can only be passed to methods of the world it was created with,
        // so keep both handles alive for as long as you run queries.
        m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 2048);
    }

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