Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavWorld.GetNodeType

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 NavNodeType GetNodeType(NavNode node);

Parameters

Parameter Description
node The identifier of a node from a NavMesh surface or link.

Returns

NavNodeType Polygon when the node is a polygon on a NavMesh surface.

Link when the node is a NavMesh Link or a generated link baked into a NavMeshData object.

Undefined when the node is empty and no query has produced it.

Description

Determines whether the NavMesh node is a polygon or a link.

Unity encodes the type in the NavNode identifier itself, so you can determine the type even after the specified node becomes invalid in the query's NavWorld. Use this method to decide whether to treat a node as a NavMesh surface polygon or as a link before you inspect its geometry.

Additional resources: NavNodeType

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

public class GetNodeTypeExample : MonoBehaviour
{
    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation location = world.MapLocation(transform.position, Vector3.one, 0);
        if (!world.IsValid(location))
            return;

        NavNodeType nodeType = world.GetNodeType(location.node);
        Color color = nodeType == NavNodeType.Link ? Color.magenta : Color.green;
        Debug.DrawLine(transform.position, location.position, color);
    }
}