GetHashCode()
Computes a hash code for identifying this NavQueryBuffer in hash-based collections.
Read time 1 minuteLast updated 8 hours ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
public override readonly int GetHashCode()
Returns
Type | Description |
|---|---|
| int | A hash code derived from the buffer's internal allocation identifier. |
Remarks
The returned value is suitable for storing the NavQueryBuffer in hash-based collections such as Dictionary_2 or HashSet_1. Two values that compare equal through NavQueryBuffer.Equals also produce the same hash code. Disposing a buffer changes its hash code, so remove the buffer from any hash-based collection before you dispose it.
NavQueryBufferExamples
using System.Collections.Generic;using Unity.Collections;using UnityEngine;using Unity.AI.Navigation.LowLevel;// Attach this script to a GameObject and enter Play mode. The script uses a NavQueryBuffer as a// Dictionary key, logs its hash code, and removes the key before it disposes the buffer.public class NavQueryBufferHashExample : MonoBehaviour{ readonly Dictionary<NavQueryBuffer, string> m_Labels = new Dictionary<NavQueryBuffer, string>(); NavWorld m_World; NavQueryBuffer m_Buffer; void OnEnable() { m_World = NavWorld.GetDefaultWorld(); m_Buffer = new NavQueryBuffer(m_World, Allocator.Persistent, 1024); m_Labels[m_Buffer] = name; Debug.Log($"Registered buffer {m_Labels[m_Buffer]} with hash {m_Buffer.GetHashCode()}"); } void OnDisable() { // Drop the key before disposing, otherwise the dictionary keeps a stale buffer // whose hash no longer matches the disposed allocation. m_Labels.Remove(m_Buffer); m_Buffer.Dispose(); m_World.Dispose(); }}