Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetDefaultWorld()

Obtains a reference to the navigation mesh world where all navigation operations occur.
Read time 1 minuteLast updated 20 days ago

Definition

public static NavWorld GetDefaultWorld()

Returns

Type

Description

NavWorldA reference to the single NavWorld that can currently exist and be used in Unity.

Remarks

The returned world comprises all the NavMesh surfaces and connections that are also used through the NavMesh-related structures.
The world becomes invalid after a call to NavMesh.RemoveAllNavMeshData. A new call to
GetDefaultWorld
returns a world that is different than the one that has been destroyed.
Each call returns a separate handle that holds resources of its own. Pair every call with a NavWorld.Dispose call, for example through a
using
declaration, otherwise the handles accumulate for as long as the navigation data exists.

Examples

using UnityEngine;using Unity.AI.Navigation.LowLevel;public class GetDefaultWorldExample : MonoBehaviour{ NavWorld m_World; void OnEnable() { // Each handle owns a safety handle, so obtain one here and keep // it for as long as you run queries, instead of asking for a new // handle on every frame. m_World = NavWorld.GetDefaultWorld(); } void OnDisable() { m_World.Dispose(); } void Update() { if (!m_World.IsValid()) return; NavLocation location = m_World.MapLocation(transform.position, 100f * Vector3.one, 0); if (m_World.IsValid(location)) Debug.DrawLine(transform.position, location.position, Color.green); }}