Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavQueryBuffer.Dispose

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 void Dispose();

Description

Destroys the NavQueryBuffer and deallocates all memory used by it.

Call this method when the buffer is no longer needed. After you dispose it, the NavQueryBuffer can't be reused, and any subsequent NavWorld pathfinding call that receives it throws an exception when executed in the Editor. Each NavQueryBuffer you create must be paired with exactly one call to NavQueryBuffer.Dispose.

using Unity.Collections;
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class NavQueryBufferDisposeExample : MonoBehaviour
{
    NavWorld m_World;
    NavQueryBuffer m_Buffer;

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();
        m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 1024);
    }

    void OnDisable()
    {
        // Release the native memory allocated by the constructor, then the world handle.
        m_Buffer.Dispose();
        m_World.Dispose();
    }
}