Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavWorld.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

Releases this NavWorld handle and prevents any further operations on it.

Call this method when you no longer need to use the NavWorld. After calling it, the NavWorld becomes invalid and all of its methods return invalid results or throw exceptions when executed in the Editor. Other handles to the same navigation data aren't affected. To destroy the underlying navigation system use NavMesh.RemoveAllNavMeshData.

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

public class NavWorldLifecycleExample : 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 per-query buffer first, then release the NavWorld handle.
        m_Buffer.Dispose();
        m_World.Dispose();
    }
}