Solo Project · Procedural Generation · Unity · C#

Procedural Dungeon Generator

A developer tool I designed and built entirely in Unity — enabling multi-floor, fully navigable dungeons from custom prefabs with seed-based deterministic generation.

Unity C# BSP Trees HashSet Tilemaps NavMesh Seed Control
Visit Itch Page

How I Built It

I designed the generator around a clean separation between logical generation and visual instantiation, which kept iteration fast and let me swap visual layers without touching core logic. The pipeline runs in six distinct passes I architected from scratch.


1. Layer-Based Dungeon Generation

I generate the dungeon one floor at a time. Each layer stores its walkable tiles in a HashSet<Vector2Int> — a deliberate choice I made after early list-based prototypes became slow at scale. The switch gave O(1) lookups for wall placement and ladder detection. I create a parent object per layer to keep the Unity hierarchy clean.

Layer Generation

2. BSP Room Splitting

I chose Binary Space Partitioning to guarantee non-overlapping rooms with natural spacing. The dungeon starts as one large region which I recursively split into a BSP tree — each leaf becomes a room, with size and offset randomised within that region's bounds.

BSP Splitting Logic

3. Corridor Carving

I connect rooms using a configurable corridor carver. A "straightness" parameter I exposed lets designers choose whether corridors carve horizontally or vertically first, producing either structured grid-like layouts or more organic winding paths depending on the project's visual style.

Corridor Carving

4. Wall Placement & Ladders

After carving, I generate walls by checking each tile for missing neighbours — producing clean edges without manual placement. I then compare adjacent floor tile sets to find shared walkable positions, which become valid ladder spawn points. I fixed a bug where corridor tiles were excluded from this comparison, causing ladders to appear only inside rooms; merging corridor tiles into the floor set resolved it.

Walls & Ladders

About the Project

A fully custom procedural dungeon generation tool I built in Unity for developers. It produces multi-floor, fully navigable dungeons from any custom prefabs, with complete control over layout density, room sizes, connectivity, visual theme, and seed-based variation.


Key Features



Challenges I Solved

Performance: Early prototypes stored tiles in lists, which became slow at larger dungeon sizes. I switched to HashSet lookups, which significantly improved runtime efficiency at scale.

Connectivity: Certain seeds produced isolated rooms with no path between them. I introduced a deterministic corridor pass that guarantees every room is reachable regardless of layout randomness.

Visual Placement: Overlapping walls appeared when rooms were carved too close together. I built a tile-state validation layer that catches and resolves duplicates before instantiation.

Ladders Not Spawning in Corridors: The ladder system compared only room tiles between floors, so corridor tiles were skipped — preventing ladders from appearing outside rooms. I fixed this by including corridor tiles in the shared walkable set before the comparison runs.



What I Learned

[ close ] Screenshot