Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetHashCode()

Returns the hash code for use in collections.
Read time 1 minuteLast updated 11 days ago

Definition

public override int GetHashCode()

Returns

Type

Description

intThe hash code representing the node identifier and position of this location.

Remarks

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.

Examples

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