Documentation

Unity Engine

Download Unity

Unity Engine

Equals

Checks whether this NavNode refers to the same navigation node as another.
Read time 2 minutesLast updated 8 hours ago

Definition

Equals(NavNode)

Checks whether this
NavNode
refers to the same navigation node as another.
public readonly bool Equals(NavNode other)

Parameters

other

A
NavNode
to compare this one with.

Returns

Type

Description

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

Remarks

The comparison uses 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.

Examples

using UnityEngine;using Unity.AI.Navigation.LowLevel;// Move the gameobject and see whether it maps to a different NavMesh nodepublic class NavNodeEqualsExample : MonoBehaviour{ Vector3 m_Anchor; void OnEnable() { m_Anchor = transform.position; } void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation here = world.MapLocation(transform.position, 5f * Vector3.one, -1); NavLocation there = world.MapLocation(m_Anchor, 5f * Vector3.one, -1); if (world.IsValid(here) && world.IsValid(there)) { bool sameNode = here.node.Equals(there.node); Debug.DrawLine(here.position, there.position, sameNode ? Color.green : Color.orange); } else { Debug.DrawLine(transform.position, m_Anchor, Color.red); } if (Time.frameCount % 100 == 0) m_Anchor = transform.position; }}

Equals(Object)

Checks whether this
NavNode
refers to the same navigation node as another.
public override readonly bool Equals(object obj)

Parameters

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

Returns

Type

Description

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

Remarks

The comparison uses 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.

Examples

using UnityEngine;using Unity.AI.Navigation.LowLevel;// Move the gameobject and see whether it maps to a different NavMesh nodepublic class NavNodeEqualsExample : MonoBehaviour{ Vector3 m_Anchor; void OnEnable() { m_Anchor = transform.position; } void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation here = world.MapLocation(transform.position, 5f * Vector3.one, -1); NavLocation there = world.MapLocation(m_Anchor, 5f * Vector3.one, -1); if (world.IsValid(here) && world.IsValid(there)) { bool sameNode = here.node.Equals(there.node); Debug.DrawLine(here.position, there.position, sameNode ? Color.green : Color.orange); } else { Debug.DrawLine(transform.position, m_Anchor, Color.red); } if (Time.frameCount % 100 == 0) m_Anchor = transform.position; }}