# Spatial Hashing

## **Spatial Hashing Interest Management**

{% hint style="warning" %}
For better performance try [Hex Spatial Hashing](/docs/manual/interest-management/hex-spatial-hashing.md) instead.
{% endhint %}

First things first: **"Spatial Hashing"** sounds complicated so that we network programmers can stroke our egos. The technique is actually pretty simple, and if you used uMMORPG before then you probably remember this as **"Grid Checker"**. We go with "Spatial Hashing" anyway since that's the industry term.

### Setting Up

Add the **Spatial Hashing Interest Management** component to the same object as your **Network Manager**:

![](/files/tqQYTiSX6WFl8wF7mFHW)

### **How It Works**

Previously we **Vector3.Distance** checked each spawned entity against each connection. Instead, we put each spawned entity into a **Grid** and for each connection, we send all **8-neighbor** grid entries to it.  This is extremely fast. In early uMMORPG tests, it was 30x faster than distance checking. The algorithm is less complex, so it scales well to large amounts of entities.

![Source: https://www.dynetisgames.com/2017/04/05/interest-management-mog/](/files/-MWIFAsg-sK23fw3O_Cw)

{% hint style="info" %}
Check out Mirror's **Benchmark** example. It uses Spatial Hashing and displays a runtime slider to let you play around with the visibility range.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mirror-networking.gitbook.io/docs/manual/interest-management/spatial-hashing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
