Unity Procedural Dungeon Generator

A Tool Designed For Developers to Create Procedurally Generated Dungeons in Unity Using Custom Prefabs

Visit Itch Page

About The Project

This project is a fully custom procedural dungeon generation system built in Unity. It enables developers to create multi-floor, fully navigable dungeons using their own prefabs, with complete control over layout density, room sizes, connectivity, theme, and seed-based variation.


The tool is designed to be modular, designer-friendly, and performant, suitable for roguelikes, dungeon crawlers, and rapid prototyping environments. It separates logical generation from visual instantiation, giving developers clean control over both the underlying tilemap and the final scene objects.



Main Features

How It Works

The generator builds the dungeon in several distinct passes:



Development Challenges

Performance: Early prototypes used lists for tile storage, which became slow in larger dungeons. Switching to HashSet lookups significantly improved runtime efficiency.

Connectivity: Some seeds produced isolated rooms. A deterministic corridor pass ensures that every room is reachable, regardless of layout randomness.

Visual Placement: Overlapping walls occurred when carving rooms too close together. A dedicated tile-state validation system fixed duplicates and improved clarity.

Ladders Not Spawning in Corridors: Corridor tiles weren’t stored in the room map, so the ladder system skipped every overlapping corridor tile, preventing ladders from appearing outside rooms.



What I Learned



Development

Full Code Available on Request


1. Layer-Based Dungeon Generation

The dungeon is generated one floor at a time. Each layer stores its walkable tiles as a HashSet<Vector2Int>, which ensures extremely fast lookups when placing walls or identifying ladder positions. Parent objects are created for each layer to keep the Unity hierarchy structured and readable.

Layer Generation

2. BSP Room Splitting

The dungeon begins as one large region which is recursively split into smaller sections using a Binary Space Partition (BSP) tree. Each leaf of the tree becomes a room, with size and offset randomised inside that region.

This method ensures rooms never overlap and creates naturally spaced layouts.

BSP Splitting Logic

3. Corridor Carving

Rooms are connected using simple corridors. The generator chooses whether to carve horizontally or vertically first, based on a “straightness” parameter, allowing both structured and more organic layouts depending on the configuration.

Corridor Carving

4. Wall Placement & Ladders

After floors and corridors are carved, walls are automatically generated by checking each tile for missing neighbours. Adjacent floors are compared to detect shared walkable tiles, which become valid ladder placement points to connect multiple layers.

Walls & Ladders

×