Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetHashCode()

Obtains the hash code of this NavNode for use in collections.
Read time 1 minuteLast updated 13 days ago

Definition

public override readonly int GetHashCode()

Returns

Type

Description

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

Remarks

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.

Examples

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()}"); }}