Dispose()
Destroys the NavQueryBuffer and frees the memory it uses.
Read time 1 minuteLast updated 8 hours ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
public void Dispose()
Remarks
Call this method when the buffer is no longer needed. After you dispose it, the can't be reused, and any subsequent NavWorld pathfinding call that receives it throws an exception when executed in the Editor. Call exactly once for each NavQueryBuffer you create.
NavQueryBufferDisposeExamples
using Unity.Collections;using UnityEngine;using Unity.AI.Navigation.LowLevel;// Attach this script to a GameObject. When the GameObject is disabled, the script disposes the// NavQueryBuffer and the NavWorld handle to free their native memory.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(); }}