Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavNode.IsNull

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 bool IsNull();

Returns

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

Description

Determines whether this NavNode is empty of any information.

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 NavNode.IsNull still returns false. Use NavWorld.IsValid to check whether a non-null node is currently active in the NavMesh.

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

public class NavNodeIsNullExample : MonoBehaviour
{
    NavNode m_Stored;

    void Update()
    {
        // Default-initialized NavNode values are null until you assign one from a NavWorld query.
        if (m_Stored.IsNull())
        {
            using NavWorld world = NavWorld.GetDefaultWorld();
            NavLocation location = world.MapLocation(transform.position, Vector3.one, 0);
            if (world.IsValid(location))
                m_Stored = location.node;
        }
    }
}