---
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/navworld/gethashcode
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/gethashcode.md
last_updated: 2026-11-30
generated_at: 2026-12-01T01:56:02.862Z
locale: en-us
---

# GetHashCode()

> Calculates the hash code for use in 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) | The hash code derived from the internal identifier of this `NavWorld`, suitable for use in hash-based collections. |

### Remarks

The returned value is derived from the internal identifier of the [NavWorld](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld.md) and is suitable for storing worlds in hash-based collections such as `Dictionary` or `HashSet`. Two `NavWorld` values that compare equal through [NavWorld.Equals](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/equals.md) also produce the same hash code.

The reverse doesn't hold. Two `NavWorld` handles that refer to different navigation data can produce the same hash code, so a matching hash code on its own doesn't establish that two handles are the same. Use [NavWorld.Equals](/engine/7000.0/script-reference/unity/ai/navigation/lowlevel/navworld/equals.md) or the `==` operator whenever you need to determine that.

### Examples

```csharp
using UnityEngine;
using UnityEngine.AI;
using Unity.AI.Navigation.LowLevel;

public class NavWorldEqualityExample : MonoBehaviour
{
    [Tooltip("Allows this example to remove every NavMesh in the scene when it's enabled in Play Mode, " +
        "or from the component's context menu. They return only after exiting Play Mode.")]
    public bool allowRemovingAllNavMeshData;

    NavWorld m_World;
    int m_CachedWorldHash;

    void OnEnable()
    {
        m_World = NavWorld.GetDefaultWorld();
        m_CachedWorldHash = m_World.GetHashCode();
        Debug.Log($"Cached the NavMesh world hash {m_CachedWorldHash}");

        if (Application.isPlaying && allowRemovingAllNavMeshData)
        {
            // Destroying all the data makes every existing handle to the old world invalid.
            NavMesh.RemoveAllNavMeshData();
            Debug.Log("Removed all NavMesh data.");
        }

        CompareNavigationWorldToPrevious();
    }

    public void CompareNavigationWorldToPrevious()
    {
        NavWorld currentWorld = NavWorld.GetDefaultWorld();

        // Equals, == and != compare the underlying navigation system rather than the struct copy.
        if (currentWorld == m_World)
        {
            Debug.Log("The navigation world is the same as before.");

            // The handles are interchangeable, so keep one and release the duplicate.
            currentWorld.Dispose();
            return;
        }

        Debug.Log($"The world was re-created: hash {m_CachedWorldHash} became {currentWorld.GetHashCode()}");

        // Release the stale handle before replacing it, otherwise its safety handle leaks.
        m_World.Dispose();
        m_World = currentWorld;
        m_CachedWorldHash = m_World.GetHashCode();
    }

    void OnDisable()
    {
        m_World.Dispose();
    }
}
```
