Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavNode.GetHashCode

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 int GetHashCode();

Returns

int The hash code derived from the node identifier, suitable for use in hash-based collections.

Description

Obtains the hash code of this NavNode for use in collections.

The returned value is derived from the internal identifier of the NavNode and is suitable for storing nodes in hash-based collections such as Dictionary or HashSet. Two NavNode values that compare equal through NavNode.Equals also produce the same hash code.

using System.Collections.Generic;
using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class NavNodeHashExample : MonoBehaviour
{
    readonly HashSet<NavNode> m_VisitedNodes = new HashSet<NavNode>();

    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation location = world.MapLocation(transform.position, Vector3.one, 0);
        if (world.IsValid(location) && m_VisitedNodes.Add(location.node))
            Debug.Log($"Recorded new node, hash {location.node.GetHashCode()}");
    }
}