Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavLocation.operator ==

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

public static bool operator ==(NavLocation left, NavLocation right);

Parameters

Parameter Description
left The NavLocation on the left side of the operator.
right The NavLocation on the right side of the operator.

Returns

bool true if the two NavLocation values share the same node and position, false otherwise.

Description

Checks whether two NavLocation objects have the same position and refer to the same NavMesh node.

This operator is a syntactic shortcut equivalent to calling NavLocation.Equals. Use it inside expressions where the == syntax is more concise than an explicit method call. Both the position and the node are compared.

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

public class NavLocationEqualOperatorExample : MonoBehaviour
{
    NavLocation m_Previous;

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation current = world.MapLocation(transform.position, Vector3.one, 0);
        if (current == m_Previous)
            Debug.Log("Agent has not moved to a new NavMesh location.");
        m_Previous = current;
    }
}