bool
true if the NavWorld has been properly initialized, or false if the underlying navigation system has been destroyed.
Checks whether the NavWorld has been properly initialized.
The only way to obtain the single possible valid NavMesh world is through a call to NavWorld.GetDefaultWorld. A NavWorld becomes invalid after a call to NavMesh.RemoveAllNavMeshData destroys the underlying navigation data. Use this method before you invoke any other NavWorld operation, to avoid exceptions that Unity throws in the Editor.
using UnityEngine; using Unity.AI.Navigation.LowLevel; public class IsValidWorldExample : MonoBehaviour { void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); if (!world.IsValid()) { Debug.LogWarning("No valid NavMesh world is currently available."); return; } NavLocation location = world.MapLocation(transform.position, Vector3.one, 0); if (world.IsValid(location)) Debug.DrawLine(transform.position, location.position, Color.green); } }
| Parameter | Description |
|---|---|
| node | The identifier of the NavMesh node to check. |
bool
true if the node referenced by the specified NavNode is active in the NavMesh. Otherwise, false.
Checks whether the node referenced by the specified NavNode is active in the NavMesh.
NavMesh nodes become invalid when Unity removes the NavMesh surface or the links they belong to, or when a modification of the NavMesh in their region replaces them. Calls to NavMesh.RemoveNavMeshData or NavMesh.RemoveLink remove NavMesh surfaces and links. Calls to NavMeshBuilder.UpdateNavMeshData, or carving the NavMesh with a NavMeshObstacle, modify the NavMesh.
using UnityEngine; using Unity.AI.Navigation.LowLevel; public class IsValidNodeExample : MonoBehaviour { NavNode m_CachedNode; void Start() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(transform.position, Vector3.one, 0); m_CachedNode = location.node; } void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); if (!world.IsValid(m_CachedNode)) Debug.LogWarning("Cached node was removed or replaced; re-map the location."); } }
| Parameter | Description |
|---|---|
| location | The location on the NavMesh to check. Checking the location is the same as checking location.node directly. |
bool
true if the node referenced by the NavNode contained in the NavLocation is active in the NavMesh. Otherwise, false.
Checks whether the node referenced by the NavNode contained in the NavLocation is active in the NavMesh.
A NavLocation returned by NavWorld.MapLocation can become invalid if the NavMesh data changes around its position, for example through carving by a NavMeshObstacle or a NavMeshBuilder.UpdateNavMeshData call. Verify the location before passing it to other NavWorld operations.
using UnityEngine; using Unity.AI.Navigation.LowLevel; public class IsValidLocationExample : MonoBehaviour { public Transform target; void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation location = world.MapLocation(target.position, Vector3.one, 0); if (!world.IsValid(location)) return; Debug.DrawLine(transform.position, location.position, Color.cyan); } }