Skip to content

Core Concepts: Dungeon Generator

Overview

The Dungeon Generator is the engine responsible for taking all your configuration (from the Dungeon Flow, Archetypes, Tile Sets, etc.) and actually building the dungeon layout in your scene.

While you can trigger generation manually through code or via an editor window (Window > DunGen > Generate Dungeon), the most common way to handle generation at runtime is by using the Runtime Dungeon component.

You add this component to a GameObject in your scene (Add Component > DunGen > Runtime Dungeon). This GameObject then becomes the central point for controlling and triggering the dungeon generation process for that specific dungeon instance.


Runtime Dungeon Component Settings

Here are the settings available in the Runtime Dungeon component's Inspector:

  • Generate on Start:

    • If checked, the dungeon generation process will automatically begin as soon as the scene starts (in the Start() method). If unchecked, you'll need to trigger generation manually via code or another system (like PlayMaker).
  • Root:

    • An optional GameObject reference. If assigned, the generated dungeon's root GameObject (containing all the placed Tiles) will be parented under this object in the scene hierarchy. If left as None, DunGen will create a new root GameObject named "Dungeon".
  • Dungeon Flow:

    • Required. Assign the Dungeon Flow asset that defines the structure and rules for the dungeon you want to generate. This is the master blueprint the generator follows.
  • Max Failed Attempts:

    • Specifies the maximum number of times DunGen is allowed to completely fail and restart the generation process in the editor before giving up. This prevents infinite loops during design if constraints are too strict.

Runtime Behaviour

In a standalone build (not the Unity Editor), DunGen will keep retrying indefinitely until it succeeds, ignoring this setting to ensure a dungeon is always generated eventually.

  • Length Multiplier:

    • A multiplier applied to the Length range defined in the assigned Dungeon Flow asset.
    • 1 = Use the length as defined in the Dungeon Flow.
    • 2 = Double the target length range.
    • 0.5 = Halves the target length range.
    • This allows you to easily scale the dungeon size without modifying the Dungeon Flow asset itself.
  • Up Direction:

    • Defines the primary "up" axis for the dungeon layout (usually +Y for 3D, and -Z for top-down 2D). This primarily affects the placement logic for vertically oriented doorways, ensuring they connect correctly relative to the dungeon's intended orientation. It does not rotate the entire generated dungeon.
  • Debug Render:

    • If checked, coloured bounding boxes will be rendered around each Tile in the Scene view after generation is complete.
      • Main Path: Tiles are coloured from Red (near Start) to Green (near Goal).
      • Branch Paths: Tiles are coloured from Blue (near branch start) to Purple (near branch end).
    • Useful for visualizing the generated layout structure and debugging path generation.

Asynchronous Generation

Settings related to generating the dungeon over multiple frames to avoid freezing the game.

  • Generate Asynchronously:
    • If checked, the dungeon generation process will be spread across multiple frames instead of happening all at once. This prevents the game from hanging during potentially long generation times, allowing loading screens or animations to continue playing.

Note

Asynchronous generation might take slightly longer overall compared to synchronous generation.

  • Max Frame Time:

    • (Only used if Generate Asynchronously is checked). The maximum time (in milliseconds) that DunGen is allowed to spend on generation tasks within a single frame. Lower values lead to better game responsiveness during generation but increase the total generation time. Higher values shorten total generation time but might cause noticeable frame stutters.
  • Pause Between Rooms:

    • (Only used if Generate Asynchronously is checked). An optional delay (in seconds) to pause after placing each room. Primarily useful for visualizing the step-by-step generation process for debugging purposes. Set to 0 for normal asynchronous generation. This is automatically disabled in standalone builds.

Collision

Settings controlling how tiles interact spatially.

  • Trigger Placement:

    • If enabled, DunGen will automatically add a BoxCollider (or BoxCollider2D) component as a trigger to the root of each placed Tile prefab. These triggers encompass the bounds of the tile. This should be set to match the type of dungeon you're making (2D or 3D).
    • Can be used in conjunction with the DunGen Character Component or your own scripts to detect when an object enters/exits a specific tile area.
  • Trigger Layer:

    • Specifies the physics layer on which the auto-generated Tile Triggers (if enabled above) should be placed.
  • Overlap Threshold:

    • A small value determining how much two connected tiles are allowed to overlap spatially. Usually doesn't need changing.
  • Collide All Dungeons:

    • If checked, DunGen will check for collisions against tiles from all previously generated dungeons in the scene, not just the tiles within the dungeon currently being generated. Useful if you have multiple independent DunGen instances active.
  • Disallow Overhangs?:

    • If checked, tiles are prevented from being placed vertically above or below other tiles if their X/Z bounds overlap.
  • Padding:

    • The minimum amount of empty space that must exist between the bounding boxes of any two unconnected tiles. Helps prevent unwanted visual overlap and clutter.

Constraints

Settings for restricting where tiles can be placed.

  • Restrict to Bounds?:

    • If checked, DunGen will only place tiles within the volume defined by the Placement Bounds below.
  • Placement Bounds:

    • (Only used if Restrict to Bounds? is checked). Defines a world-space bounding box (Center and Extents) outside of which no tiles can be generated.

Warning

Using bounds restrictions can significantly increase the chance of generation failure if the bounds are too small for the requested dungeon length and complexity. It may also increase generation time.


Global Overrides

These settings allow you to optionally override specific behaviours for all tiles generated by this component, regardless of their individual Tile Component settings. If an override is not enabled, the behaviour is determined per-tile.

Active Override

The checkbox to the left of the setting determines whether the override is active or not.

  • Repeat Mode:

    • Forces all tiles to adhere to a specific repeat mode (Allow, Disallow Immediate, Disallow), overriding any Repeat Mode set on individual Tile components. Defaults to Allow. See Repeat Mode on the Tiles page for details.
  • Allow Tile Rotation:

    • Forces all tiles to either allow rotation or disallow rotation, overriding any Allow Rotation setting on individual Tile components.

The Runtime Dungeon component is the primary interface for launching and controlling the DunGen process within your game scene.