---
title: NavQueryBuffer(NavWorld, Allocator, int)
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/ctor
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/ctor.md
last_updated: 2026-11-30
generated_at: 2026-12-01T01:18:13.769Z
locale: en-us
---

# 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/7000.0/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** [UnityEngine.AIModule](/engine/7000.0/script-reference/modules/unityengine-aimodule.md)

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

### Parameters

**** (\[NavWorld]\(/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld)): The [NavWorld](/engine/7000.0/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/7000.0/script-reference/unity/collections/allocator)): The allocator type that sets the lifetime of the buffer's safety handle. Unity always allocates the native buffer memory as persistent. With collections checks enabled, a buffer created with [Allocator.Temp](/engine/7000.0/script-reference/unity/collections/allocator/temp.md) becomes invalid at the end of the scope where you create it.**** (\[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](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/beginfindpath.md), [NavWorld.ContinueFindPath](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/continuefindpath.md), [NavWorld.EndFindPath](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/endfindpath.md), and [NavWorld.GetResultFromFindPath](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/getresultfromfindpath.md). If the buffer is too small for the search, the pathfinding method returns a [NavQueryStatus.MaxNodesToVisitExceeded](/engine/7000.0/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.

In the Editor, the constructor throws an ArgumentException if `world` isn't valid, and an OutOfMemoryException if Unity can't allocate the buffer.

For more information about the container type that this buffer follows, refer to [Introduction to NativeContainer](/engine/7000.0/manual/scripting/programming-distribute-work-threads/job-system/thread-safe-types/native-container.md).

### Examples

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

// Attach this script to a GameObject. When the GameObject is enabled, the script creates a
// NavQueryBuffer that can store up to 2048 nodes. It disposes the buffer when the GameObject is disabled.
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();
    }
}
```
