Cyclic lock-and-key dungeon generation on a grid for Unreal Engine.
Cyclic lock-and-key dungeon generation on a grid for Unreal Engine.
NsDungeons makes dungeon floors with a lock-and-key structure, after the cyclic method of Unexplored. It gives an abstract graph on a fixed grid (rooms, doors, locks, keys, one-way doors, and hidden doors) and a cell layout of that graph. An editor tab shows each step of a generation.
NsDungeons does not build game floors, move characters, or find paths. Your game builds its floor from the layout. The demo actor builds a plain greybox floor only to show the plugin.
Camp on rooms, by place.NsDungeons folder into the Plugins folder of your project."NsDungeons" to the dependencies of the game module that calls the generator.NsDungeonRuleSet.#include "NsDungeonGenerator.h"
const FNsDungeonResult Result = FNsDungeonGenerator::Generate(RuleSet->Settings, Seed);
if (Result.bValid)
{
for (const FNsDungeonNode& Node : Result.Graph.Nodes)
{
// Node.Role, Node.Coord, Node.Tags: one room for each used node
}
// Result.Layout: Cells, Rooms, and Doors for the floor builder
}
In Blueprint, Generate Dungeon (rule set, seed) returns the result with its graph and its layout. Get Layout Cell, Cell To Local, and Local To Cell read the cells.
To see the plugin work, open the map /NsDungeons/Demo/L_NsDungeonsDemo and click Play. Push N or P to change the seed, and R for a random seed. Push 1 to 8 to show the graph of a step, and 0 to hide it.
| Type | Shape |
|---|---|
Simple |
Two routes to the goal, no lock |
LockAndKey |
The goal is behind a lock. Its key is at the end of the other route, which a one-way door closes off from the goal |
TwoKeys |
As LockAndKey, with a second key halfway along the locked route |
OneWayValve |
One route to the goal. The other route is a one-way way back from the goal |
FNsDungeonGraph โ A fixed grid of nodes, the edges between grid neighbors, and the lock and key lists.FNsDungeonEdge โ Two nodes and a kind: Open, Locked, OneWay, or Hidden.FNsDungeonLock / FNsDungeonKey โ A locked edge and the keys that it needs, and the node that holds each key.FNsDungeonLayout โ The cells, the rooms, and the doors of a dungeon.FNsDungeonSettings / UNsDungeonRuleSet โ The values of one generation, and the asset that holds them.FNsDungeonResult โ The seed that worked, the validity, the graph, the layout, and the steps.FNsDungeonGenerator::Generate โ Make a dungeon. Pass true as the third argument to keep each step.FNsDungeonGenerator::Validate โ Check a hand-made graph.UNsDungeonLibrary โ Blueprint calls: generate, read a cell, cell to local, and local to cell.UNsDungeonDebugComponent โ The play overlay. Call SetDungeon, then set NsDungeons.ShowDebug 1.ANsDungeonDemoActor โ The greybox demo floor.The generation follows the cyclic dungeon method of Unexplored, as Boris the Brave describes it (2021).