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
- Type: Constructor
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
public NavQueryBuffer(NavWorld world, Allocator allocator, int maxNodesToVisit = 1024)
Parameters
The label indicating the desired lifetime of the object. The parameter has no effect; the buffer is always allocated as Persistent.
allocatorThe 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 parameter to size the buffer for the pathfinding methods that use it, such as , , , and . If the buffer is too small for the search, the pathfinding method returns a NavQueryStatus.MaxNodesToVisitExceeded status. Unity clamps 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.
maxNodesToVisitNavWorld.BeginFindPathNavWorld.ContinueFindPathNavWorld.EndFindPathNavWorld.GetResultFromFindPathmaxNodesToVisitFor 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(); }}