https://github.com/trentsterling/spatialhash
🚀 High-performance, generic Spatial Hash for Unity. Architected for O(1) performance, zero allocations, and data-oriented simplicity. Includes multi-part masterclass tutorial.
https://github.com/trentsterling/spatialhash
aoi csharp gamedev high-performance masterclass netcode optimization spatial-hash spatial-partitioning unity
Last synced: about 4 hours ago
JSON representation
🚀 High-performance, generic Spatial Hash for Unity. Architected for O(1) performance, zero allocations, and data-oriented simplicity. Includes multi-part masterclass tutorial.
- Host: GitHub
- URL: https://github.com/trentsterling/spatialhash
- Owner: TrentSterling
- Created: 2026-02-14T10:47:00.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2026-02-14T12:42:50.000Z (5 months ago)
- Last Synced: 2026-02-14T19:39:18.003Z (5 months ago)
- Topics: aoi, csharp, gamedev, high-performance, masterclass, netcode, optimization, spatial-hash, spatial-partitioning, unity
- Language: HTML
- Homepage: http://tront.xyz/spatialhash/
- Size: 202 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ⚡ SpatialHash Masterclass
[](https://opensource.org/licenses/MIT)
[](http://tront.xyz/spatialhash/)
[](#)
A high-performance, generic **Spatial Hash** for Unity. Architected for O(1) performance, zero allocations, and data-oriented simplicity.
## 🚀 Live Masterclass & Interactive Demos
Explore the 5-part technical deep-dive, interactive visualizers, and the **Pixel Pickup** stress-test arena at:
**[http://tront.xyz/spatialhash/](http://tront.xyz/spatialhash/)**
---
## 📦 The Toolkit
This repository contains a production-ready spatial partitioning suite:
### 1. [SpatialHash.cs](spatialhash/SpatialHash.cs) (Core API)
The generic, non-allocating 3D hash engine.
- **Generic**: Works with any component or class.
- **Bucket Pooling**: Zero-allocation internal memory recycling.
- **Query Types**: High-speed Sphere and AABB checks.
### 2. [NetworkAOI.cs](spatialhash/NetworkAOIManager.cs) (Networking)
Plug-and-play Interest Management for **PurrNet**, FishNet, and Mirror.
- Sync only what matters to each player.
- Save 90% of your network bandwidth.
### 3. [RoomManager.cs](spatialhash/RoomManager.cs) (World State)
Portal-based visibility and room synchronization logic (Inspired by **CellGen**).
### 4. [Samples Gallery](spatialhash/Examples/)
Complete implementations for:
- **CollisionBroadphase**: 10x faster trigger systems.
- **PathfindingLookup**: Fast nearest-node search.
- **WorldStreamer**: Dynamic level/chunk loading.
- **FrustumCulling**: Broad-phase visibility filtering.
---
## 🛠️ Quick Start
```csharp
using SpatialHash;
// 1. Initialize (Cell size should be ~2x your query radius)
var hash = new SpatialHash(cellSize: 10f);
// 2. Register/Update (O(1))
hash.Update(myEntity, myEntity.position);
// 3. Query (Zero-Allocation)
List results = new List();
hash.QueryRadius(playerPosition, 20f, results);
```
---
## 📜 License
MIT - Created for the community by **Trent Sterling**.
Come say hi on [Discord](https://discord.gg/0hyoWZyM6y7kkFCN)!