Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavQueryBuffer Constructor

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

Cancel

Declaration

public NavQueryBuffer(NavWorld world, Allocator allocator, int maxNodesToVisit);

Parameters

Parameter Description
world 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.

Description

Creates a new buffer and allocates memory to store the intermediate NavMesh node data used by pathfinding operations.

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.

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