---
title: GetHashCode()
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/gethashcode
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/gethashcode.md
last_updated: 2026-11-30
generated_at: 2026-12-01T01:17:58.550Z
locale: en-us
---

# GetHashCode()

> Computes a hash code for identifying this NavQueryBuffer in hash-based collections.

## Definition

* **Type:** Method
* **Namespace:** [Unity.AI.Navigation.LowLevel](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel.md)
* **Assembly:** [UnityEngine.AIModule](/engine/7000.0/script-reference/modules/unityengine-aimodule.md)

```csharp
public override readonly int GetHashCode()
```

### Returns

| Type                                                       | Description                                                           |
| ---------------------------------------------------------- | --------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | A hash code derived from the buffer's internal allocation identifier. |

### Remarks

The returned value is suitable for storing the [NavQueryBuffer](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer.md) in hash-based collections such as Dictionary\_2 or HashSet\_1. Two `NavQueryBuffer` values that compare equal through [NavQueryBuffer.Equals](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navquerybuffer/equals.md) 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.

### Examples

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