Dungeon Generator

Wave-function-collapse dungeon generation for Unity 6 URP, with runtime building, live painting, six themes, stacked floors, gameplay hooks, NavMesh agents, editor tools, and a complete interactive demo.

Version 1.6.1 Unity 6 URP 17 Full C# source

Overview

Dungeon Generator creates connected, playable, isometric-style stone dungeons from a deterministic seed. Its pure-C# WFC core solves tile adjacency and carving, while the Unity runtime builds modular floors, walls, doors, canals, cave rims, graveyards, props, lighting, gameplay elements, and navigation.

The generated result remains editable. Paint terrain families, stamp exact tiles, restyle individual walls, swap themes and models, tune weights, undo changes, serialize a complete dungeon code, or query the solved plan from your own systems.

Installation and requirements

  1. Import the package into a Unity 6 project.
  2. Install or enable the Universal Render Pipeline package. The bundled materials target URP 17.
  3. Keep uGUI installed if you want to use the included interactive demo. The core generator does not depend on the demo UI.
  4. Open Assets/DungeonKit/Demo/Scenes/DungeonKitDemo.unity to explore the complete feature set.

Starting from a non-URP project? Use Tools > Dungeon Kit > Setup URP. The tool lists the project settings it proposes to change and waits for confirmation.

Quick start

  1. Choose GameObject > Dungeon Kit > Dungeon Generator.
  2. The included StoneKitLibrary is located and assigned automatically.
  3. Select the new object and press Generate in its Inspector.
  4. Change the seed, grid size, outline, carving, decoration, or theme settings and generate again.

The art kit is already baked under Assets/DungeonKit/Art. Tools > Dungeon Kit > Build Demo Assets is an authoring command that rebuilds and overwrites those generated art assets; use it only when intentionally changing the art-generation code.

Feature guide

Generation

Deterministic weighted WFC with propagation and backtracking, rectangle/ellipse/diamond/cross footprints, connectivity repair, entrances, exits, guaranteed treasure, and reproducible seeds.

Terrain and painting

Cave, graveyard, void, and canal carving; cell painting and erasing; local perturbation; exact wall/door/corner/canal stamps; local re-solving; and undo.

Floors and progression

One to three independently solved floors joined by stairwells, optional terraces and basements, critical-path key/lock progression, room purposes, and furnished spaces.

Art direction

Stone, Crypt, Moss, Blocks, Rough, and Sewer themes; wall variants; modular prefab replacement; density-controlled props; atmosphere, torch, light, and audio controls.

Gameplay

Interactive chests, spike traps, collectible keys, opening gates, event callbacks, click-to-move player, runtime navigation, zombie agents, and deterministic spawn rules for your prefabs.

Tools and sharing

Dungeon Designer window, minimap, validation and region overlays, 2D raster export, PNG export in the demo, dungeon codes, URL seed/code loading in WebGL, and OBJ model swaps.

Interactive demo workflow

The demo intentionally exposes the generator’s major systems in one place. A useful evaluation path is:

  1. Set the seed, width, height, animation speed, and footprint shape, then generate.
  2. Try presets, cave bites, void bites, graveyards, canals, stacked floors, terraces, basements, and key-lock progression.
  3. Switch to Paint to add or erase terrain, perturb a cell, toggle torches, or stamp an exact structural tile.
  4. Switch among all six themes and adjust atmosphere, sun, clutter, torch density, flicker, and tile weights.
  5. Build the NavMesh, spawn the player and zombie population, enable path display, and click the dungeon to move.
  6. Use Models & Swaps to select a bundled variation or import an OBJ for a supported slot.
  7. Copy a dungeon code, reload it, export a PNG, or supply ?seed= / ?code= to a hosted WebGL demo URL.

Runtime API

Generate, edit, and query

using DungeonKit;
using DungeonKit.Core;

var gen = GetComponent<DungeonGenerator>();
gen.settings.width = 16;
gen.settings.height = 12;
gen.settings.seed = 12345;
gen.settings.caveBites = true;
gen.settings.forceCanal = true;
gen.Generate();

gen.PaintCell(4, 5, PaintKind.Cave, autoSolve: true);
gen.PerturbCell(7, 3);
gen.EraseCell(4, 5, autoSolve: true);
gen.Undo();

bool walkable = gen.IsWalkable(x, y);
bool passable = gen.IsPassable(x, y, dir); // 0=N, 1=E, 2=S, 3=W
Vector3 world = gen.CellToWorld(x, y);
DungeonPlan plan = gen.Plan;

Depth, sharing, agents, and events

DungeonQuery query = gen.Query;
int depth = query.DepthFromEntrance(cell);
float normalized = query.NormalizedDepth(cell);
bool onCriticalPath = query.IsOnCriticalPath(cell);

string code = gen.SaveCode();
if (!gen.LoadCode(code, out string error))
    Debug.LogError(error);

var player = GetComponent<DungeonPlayerSpawner>().Spawn();
player.MoveTo(worldPoint);
GetComponent<DungeonNpcSpawner>().SetPopulation(12);

DungeonEvents.ChestOpened += position => DropLoot(position);
DungeonEvents.TrapTriggered += position => DamagePlayerNear(position);
DungeonEvents.GateUnlocked += lockIndex => Fanfare();

Pure-C# generation

var settings = new GenerationSettings { width = 20, height = 14, seed = 7 };
var model = new DungeonModel(settings);
model.Generate();
DungeonPlan plan = model.Plan;

Customization

Replace the art

Open Assets/DungeonKit/Art/StoneKitLibrary.asset. Each module is a prefab slot. Walls and edge strips are authored along the north edge of a 4 × 4 metre tile and rotated by the builder. Replace compatible slots with your own prefabs and use tileSize to rescale the grid.

Tune generation

GenerationSettings.weights exposes wall density, canal amount and curvature, cave/void/grave prevalence, open-space boost, and related weights. Generate() rebuilds the logical tile catalog before solving. If you change weights and immediately perform a local edit without regenerating, call RebuildCatalog() first.

Spawn your own content

Add rules to DungeonSpawnRules to scatter project prefabs by depth band, terrain family, chance, cap, and wall alignment. Placement is deterministic for a given dungeon seed.

Performance guidance

Compatibility

UnityBuilt with Unity 6000.0.62f1. Unity 6 (6000.0) or newer is required.
RenderingUniversal Render Pipeline required for the bundled materials; the project uses URP 17.0.4.
UIuGUI is used by the demo. The generation runtime remains separate from the demo assembly.
InputThe demo supports old, new, or both input-backend settings. The Input System package is optional and is only needed when the project selects the new backend.
PlatformsWindows 64-bit and WebGL demo builds have been produced from this project. Other targets have not been claimed as verified.
Colour spaceThe bundled art is authored for Linear colour space.

Troubleshooting

Materials are magenta

The project is not using URP or the package is missing. Install URP and use Tools > Dungeon Kit > Setup URP, or assign your own materials and prefabs in the tile library.

The demo UI does not receive clicks

If Active Input Handling is set to Input System (New), install com.unity.inputsystem. The demo creates the matching EventSystem module at runtime.

Painting does not reflect newly changed tile weights

Generate once after changing weights, or call RebuildCatalog() before a paint, perturb, erase, or stamp operation.

A large dungeon rebuild is slow

Reduce clutter and torch density, avoid rebuilding every frame, and enable runtime culling. Build once and use the query/event APIs for gameplay whenever possible.

Imported OBJ scale or pivot is unsuitable

The runtime importer normalizes supported model slots to their expected footprint and pivots geometry to its base. For exact production control, prepare and assign a Unity prefab directly in the tile library.

Version 1.6.1 highlights

License and attribution

Use of this package is governed by the license under which it was acquired through the Unity Asset Store. Unity packages referenced as project dependencies remain governed by their respective Unity terms. No separate third-party content notice is included with this asset.

Support

For questions, bug reports, or feature requests, contact szekipapa77@gmail.com. Include your Unity version, target platform, a short reproduction description, and relevant Console output or screenshots.