Guide
Game procedural generation explained
Handcrafting every dungeon room, loot drop, and landscape tile does not scale — and players burn through static content fast. Procedural content generation (PCG) uses algorithms plus controlled randomness to produce levels, items, quests, and worlds that feel fresh on every run while staying within design constraints. Done well, PCG creates the “one more run” loop that powers roguelikes, open-world exploration, and live-service variety. Done poorly, it produces nonsensical layouts, unwinnable seeds, and the sense that the game is random rather than surprising. This guide covers seeded determinism, dungeon and tile algorithms, hybrid handcrafted pipelines, validation and playability testing, multiplayer sync, performance budgets, and how PCG connects to roguelike design, terrain generation, and level design flow.
What procedural generation is (and is not)
PCG is any pipeline where algorithms — not a human placing every asset — decide part of the final content. That includes dungeon room graphs, weapon stat rolls, quest parameterization, vegetation scatter on a heightmap, and narrative beat ordering. The output can be generated at edit time (bake levels in the editor), load time (build the first chunk when the player enters), or runtime (stream new areas as the player moves).
PCG is not the same as pure randomness. Players tolerate variance in loot rarity and enemy placement; they reject layouts with no path to the exit, rooms that clip through each other, or difficulty spikes with no telegraph. Strong PCG systems encode constraints — minimum room counts, connectivity guarantees, biome adjacency rules, loot tier caps — and use randomness only inside those guardrails. Think of the algorithm as a chef and the seed as which ingredients get picked from a curated pantry.
Seeded randomness and determinism
Almost every production PCG pipeline starts with a seed: an integer or string hashed into a pseudo-random number generator (PRNG). Given the same seed and the same algorithm version, every client produces identical output — critical for replays, bug reports (“seed 847291, floor 3 softlocks”), and networked games where one authority generates and others verify.
Use a well-tested PRNG (PCG, xoshiro, or your engine’s built-in) and
never mix system random calls into the generation path — OS
entropy, thread timing, and unordered hash maps all break determinism across
platforms. Derive sub-seeds per subsystem (hash(worldSeed, "dungeon"),
hash(worldSeed, "loot")) so changing loot tables does not reshuffle
the entire dungeon layout.
For daily challenges or shared leaderboards, publish a public seed and freeze the generator version in the build. When you patch generation logic, version the algorithm and keep old seeds reproducible in a “legacy mode” if competitive integrity matters.
Dungeon and level layout algorithms
Indoor and grid-based PCG usually follows one of several families:
Binary space partitioning (BSP)
Recursively split a rectangle into smaller rooms, connect sibling rooms with corridors, then place doors and encounters. BSP is fast, guarantees connectivity, and produces classic roguelike floor plans. Tune minimum room size, corridor width, and “extra loop” passes that add cycles so backtracking is not mandatory.
Graph grammars and room templates
Define a set of handcrafted room prefabs (start, combat, treasure, boss, shop) and a grammar that specifies legal connections: “combat connects to corridor or treasure, never directly to boss.” A generator walks the graph, instantiates prefabs, and stitches doorways. This hybrid approach — algorithm picks which room, artists built what it looks like — is how many commercial roguelites stay readable while feeling varied.
Cellular automata and maze carving
Start with noise-filled grids, apply birth/death rules to carve caves, or use recursive backtracker / Prim’s algorithms for perfect mazes, then punch extra holes for loops. Great for organic caves; pair with pathfinding and navmesh baking to confirm agents can reach objectives.
Wave Function Collapse (WFC)
WFC treats level design as a constraint-satisfaction problem: each tile has allowed neighbors defined by an example map or rule set. The solver propagates constraints until the grid collapses to a single tile per cell or fails. WFC excels at structured 2D tiles (platformer chunks, town blocks, Zelda-like rooms) but can deadlock — implement backtracking, fallback tiles, or pre-placed anchor cells for critical paths.
Loot, encounters, and narrative parameterization
PCG extends beyond geometry. Loot tables with weighted rolls, pity counters, and tier gates turn a finite item pool into long-tail drops — see loot tables and weighted random for the math. Encounter tables pick enemy compositions by biome, player power, and run depth; constrain them so a floor never spawns more elites than the player can reasonably handle.
Quest and dialogue PCG often means templates: “Collect {N} {item} from {biome}” with N and item drawn from tables, not generating prose from scratch. Parameterized missions scale content cheaply; fully generative narrative still needs human review for tone and coherence. Keep a library of vetted template strings and slot variables from curated lists, not open-ended LLM output in the critical path unless you have a validation layer.
Hybrid pipelines: the industry default
Pure algorithmic levels rarely ship without human-authored anchors. The practical pattern is macro handcrafted, micro procedural:
- Handcrafted — boss arenas, tutorial rooms, story beats, landmark vistas, shop hubs.
- Procedural — connector dungeons, side branches, resource scatter, minor encounter variety.
- Post-process — auto-place props, lighting probes, cover points, and pickup spawns on top of generated geometry.
Artists build modular kits (wall segments, door frames, pillar sets); the generator assembles kits into layouts and runs a beautification pass — offset props, apply decals, add ceiling details — so rooms do not look like repeated greybox blocks. Open-world games often hand-sculpt hero regions and let noise-based terrain pipelines fill the spaces between.
Validation, solvability, and playability testing
The difference between “procedural” and “broken” is validation. Automated checks should run on every generated output before the player sees it:
- Connectivity — flood-fill from start to exit; reject graphs with unreachable keys or bosses.
- Collision and navmesh — no overlapping geometry; agents can path to objectives.
- Resource budgets — enemy count, healing items, and currency within min/max curves for that depth.
- Soft constraints — maximum consecutive combat rooms, minimum safe room before boss, line-of-sight breaks.
Run batch simulation: generate 10,000 seeds overnight, log failures, histogram room counts and clear times. Monte Carlo testing catches edge cases humans miss. When a seed fails validation, either retry with a derived seed or fall back to a known-good template — never show the player a broken layout.
Multiplayer, replays, and authority
In cooperative or competitive PCG, decide who generates. Common models:
- Host authority — host runs the generator, sends a compact seed or tile list; clients rebuild locally. Lowest bandwidth; host cheating risk in PvP.
- Dedicated server — server generates and streams chunk descriptors; clients are dumb renderers. Best for anti-cheat and large worlds.
- Deterministic lockstep — all peers run identical generation from a shared seed; only inputs sync. Requires strict FP determinism and identical builds.
Replays store the seed plus input stream, not every tile placement. Document generator version in save files so old saves survive patches or migrate explicitly.
Performance, streaming, and memory
Runtime generation has a frame budget. Strategies:
- Async jobs — generate chunks on worker threads; show a loading gate or low-detail placeholder until ready.
- Incremental expansion — generate one room at a time as the player opens doors, not the entire floor at once.
- Cache and recycle — pool room instances; despawn distant chunks and regenerate from seed when revisited if memory is tight.
- LOD for PCG — coarse layout first, detail props in a second pass when the player is nearby.
Profile generation separately from rendering. A 200 ms dungeon pass is fine between floors; it is unacceptable when opening a door mid-combat.
PCG patterns by genre
| Genre | Typical PCG surface | Constraint focus |
|---|---|---|
| Roguelike / roguelite | Floor layouts, item rolls, shrine events | Fair difficulty curve, build variety, no unwinnable seeds |
| Open-world survival | Terrain, biomes, resource nodes, POI scatter | Landmark spacing, spawn safety, multiplayer chunk borders |
| Platformer | WFC tile chunks, challenge modules | Jump distance metrics, checkpoint placement |
| 4X / strategy | Maps, start positions, resource fairness | Symmetric starts, connectivity, anti-cheese spawns |
| Looter shooter | Loot affixes, mission modifiers, map tiles | Drop rate compliance, encounter density caps |
| Card / deck builders | Draft offers, map nodes, event text slots | Offer diversity, anti-duplication, power bounds |
Handcrafted vs procedural: decision guide
| Question | Lean procedural | Lean handcrafted |
|---|---|---|
| Replayability priority | High — players expect fresh layouts each run | Low — narrative pacing is fixed |
| Content team size | Small — algorithms multiply a modular kit | Large — cinematic set pieces justify labor |
| Layout readability | Rooms are modular and symmetric | Unique vistas and bespoke geometry matter |
| Multiplayer sync cost | Seed sync is cheap | Streaming large bespoke levels is heavier |
| Failure cost of bad gen | Low — retry seed or skip floor | High — one bad boss arena ruins the game |
Common mistakes
- Confusing random with varied — players notice repetition of patterns, not just room shapes. Add grammar diversity and post-process dressing.
- Skipping validation — shipping generation without automated solvability checks guarantees viral bug clips.
- Non-deterministic generation in multiplayer — unordered iteration, floating-point differences across CPUs, or time-based RNG desyncs clients.
- Generating everything at once — spikes load times; stream or stage generation to fit frame budgets.
- Overfitting to one algorithm — BSP-only dungeons feel samey; mix room templates, events, and modifiers.
- Ignoring player psychology — streaks of bad loot or hard rooms feel like the algorithm is punishing them; use pity, guarantees, and pacing rules.
- No versioning on seeds — patches that change generation break old saves and daily challenges without a version field.
Production checklist
- Document the seed format, PRNG choice, and sub-seed derivation for each subsystem.
- Run batch generation (1,000+ seeds) in CI; fail builds on connectivity or resource violations.
- Keep a debug overlay: show seed, floor index, generator version, and retry count.
- Separate generation code from gameplay logic so designers can tune tables without touching physics.
- Profile worst-case generation time on min-spec hardware; set async thresholds.
- Store generator version in saves and replay headers; plan migration for algorithm changes.
- Playtest with forced bad seeds — not only cherry-picked showcases.
- Balance procedural variety against learnability; telegraph new room types clearly.
Key takeaways
- PCG multiplies content through algorithms and constraints, not unconstrained noise.
- Seeded determinism enables replays, debugging, and cheap multiplayer sync.
- Hybrid pipelines — handcrafted templates plus procedural assembly — are the industry norm.
- Validation is non-negotiable; batch testing catches unwinnable layouts before players do.
- Match the algorithm to the genre — BSP for dungeons, WFC for tile chunks, noise for open terrain.
Related reading
- Roguelike game design explained — permadeath, run structure, and meta-progression built on procedural floors
- Game terrain generation explained — heightmaps, noise layers, biomes, and streaming open worlds
- Game level design explained — flow, pacing, and player guidance that PCG must preserve
- Game loot tables and weighted random explained — drop rates, pity systems, and server authority for procedural rewards