Documentation

Unity Engine

Download Unity

Unity Engine

IsNull()

Determines whether this NavNode is empty of any information.
Read time 1 minuteLast updated 8 hours ago

Definition

public readonly bool IsNull()

Returns

Type

Description

bool
true
if the
NavNode
has been created empty and has never pointed to any node in the NavMesh, or
false
otherwise.

Remarks

A null NavNode is the default value of the struct and represents the absence of a reference to any node. This is distinct from a
NavNode
that once referenced a real node that has since been removed; in that case
IsNull
still returns
false
. Use NavWorld.IsValid to check whether a non-null node is currently active in the NavMesh.

Examples

using UnityEngine;using UnityEngine.AI;using Unity.AI.Navigation.LowLevel;// Move the gameobject until it maps to a NavMesh polygon whose area type is not excludedpublic class NavNodeIsNullExample : MonoBehaviour{ public int excludedAreaType = 0; NavLocation m_Stored; void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); if (m_Stored.node.IsNull()) { int validAreaTypes = NavMesh.AllAreas & ~(1 << System.Math.Clamp(excludedAreaType, 0, 31)); NavLocation location = world.MapLocation(transform.position, 0.3f * Vector3.one, -1, validAreaTypes); if (world.IsValid(location)) { m_Stored = location; } Debug.DrawRay(transform.position, Vector3.up, Color.red); return; } Color statusColor = world.IsValid(m_Stored) ? Color.green : Color.yellow; Debug.DrawRay(m_Stored.position, Vector3.up, statusColor); Debug.DrawLine(transform.position, m_Stored.position, Color.gray); } void OnDisable() { m_Stored = new NavLocation(); }}