Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavNode.Equals

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 Equals(NavNode other);

Parameters

Parameter Description
other A NavNode to compare this one with.

Returns

bool true if two NavNode objects refer to the same NavMesh node, and false otherwise.

Description

Determines whether this NavNode object refers to the same navigation node as another.

The comparison is performed on the internal identifier of the node. Two NavNode values are equal even if they refer to a node that has since been removed from the NavMesh, because the identifier itself doesn't change. Use NavWorld.IsValid to determine whether the node is still active in the NavMesh world.

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

public class NavNodeEqualsExample : MonoBehaviour
{
    public Transform other;

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation here = world.MapLocation(transform.position, Vector3.one, 0);
        NavLocation there = world.MapLocation(other.position, Vector3.one, 0);

        if (here.node.Equals(there.node))
            Debug.Log("Both transforms are on the same NavMesh polygon.");
    }
}

Declaration

public bool Equals(Object obj);

Parameters

Parameter Description
obj An object to interpret as a NavNode and to compare this one with.

Returns

bool true if two NavNode objects refer to the same NavMesh node, and false otherwise.

Description

Determines whether this NavNode object refers to the same navigation node as another.

The comparison is performed on the internal identifier of the node. Two NavNode values are equal even if they refer to a node that has since been removed from the NavMesh, because the identifier itself doesn't change. Use NavWorld.IsValid to determine whether the node is still active in the NavMesh world.

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

public class NavNodeEqualsExample : MonoBehaviour
{
    public Transform other;

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation here = world.MapLocation(transform.position, Vector3.one, 0);
        NavLocation there = world.MapLocation(other.position, Vector3.one, 0);

        if (here.node.Equals(there.node))
            Debug.Log("Both transforms are on the same NavMesh polygon.");
    }
}