int The hash code representing the node identifier and position of this location.
Returns the hash code for use in collections.
The returned value combines the node identifier and the position of this NavLocation. The hash code is suitable for storing locations in hash-based collections such as Dictionary or HashSet. Two NavLocation values that compare equal through NavLocation.Equals also produce the same hash code.
using System.Collections.Generic; using UnityEngine; using Unity.AI.Navigation.LowLevel; public class NavLocationHashExample : MonoBehaviour { readonly HashSet<NavLocation> m_Visited = new HashSet<NavLocation>(); void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation current = world.MapLocation(transform.position, Vector3.one, 0); // The hash combines both the node and the exact position, so two locations on the same // polygon usually hash differently, though hash collisions are still possible. Key on // NavLocation only when the precise point matters; to track which polygons have been // visited, key on NavNode instead. if (world.IsValid(current) && m_Visited.Add(current)) Debug.Log($"Visited new location, hash {current.GetHashCode()}"); } }