NavQueryBuffer
struct in
Unity.AI.Navigation.LowLevel
Suggest a change
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close
Description
A buffer that stores intermediate node data during NavMesh pathfinding operations in a NavWorld.
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 maxNodesToVisit value in the range from 1 to 65,535, then call the following NavWorld methods in this order: BeginFindPath, ContinueFindPath (can be repeated), EndFindPath, GetResultFromFindPath. These methods store their intermediate state in the NavQueryBuffer.
NavWorld 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.
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 | Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations. |
Public 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 different underlying pathfinding buffers. |
| operator == | Checks whether two NavQueryBuffer values refer to the same underlying pathfinding buffer. |