NavQueryBuffer
A buffer that stores intermediate node data during NavMesh pathfinding operations in a NavWorld.
Read time 2 minutesLast updated 10 days ago
Definition
- Type: Struct
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
- Implements: IDisposable, IEquatable<NavQueryBuffer>
public struct NavQueryBuffer : IDisposable, IEquatable<NavQueryBuffer>
Remarks
A NavQueryBuffer is required to use the pathfinding methods of NavWorld. To obtain a path between two locations on the NavMesh, create a NavQueryBuffer with a value in the range from 1 to 65,535, then call the following NavWorld methods in this order: , (can be repeated), , . These methods store their intermediate state in the NavQueryBuffer.
maxNodesToVisitBeginFindPathContinueFindPathEndFindPathGetResultFromFindPathNavWorld pathfinding operations that use a NavQueryBuffer can be executed inside jobs (IJob, IJobFor), as opposed to the operations in the NavMesh-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
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) | Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations. |
Methods
Method | Description |
|---|---|
| Dispose | Destroys the NavQueryBuffer and deallocates all memory used by it. |
| Equals | Checks whether two NavQueryBuffer values refer to the same underlying pathfinding buffer. |
| GetHashCode | Computes a hash code for identifying this NavQueryBuffer in hash-based collections. |
Operators
Operator | Description |
|---|---|
| operator == | Checks whether two NavQueryBuffer values refer to the same underlying pathfinding buffer. |
| operator != | Checks whether two NavQueryBuffer values refer to different underlying pathfinding buffers. |