Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


NavQueryBuffer(NavWorld, Allocator, int)

Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations.
Read time 2 minutesLast updated 16 days ago

Definition

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

Parameters

The NavWorld for which this buffer is used. The buffer can be passed only to methods of the same NavWorld it was created with.

allocator

The label indicating the desired lifetime of the object. The
allocator
parameter has no effect; the buffer is always allocated as Persistent.

maxNodesToVisit

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 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

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(); }}