Skip to content

Advanced Features: Props for Variety

Creating many unique Tile prefabs can be time-consuming. DunGen offers several "Prop" components that allow you to add significant visual variety and randomness to your existing Tiles without needing to create entirely new room geometry. These components let you dynamically include, exclude, or choose between different GameObjects or prefabs within your Tiles during dungeon generation.

There are three main types of prop components:

  1. Local Prop Set: Manages a collection of existing GameObjects within a Tile, keeping some and discarding others.
  2. Random Prefab: Spawns one chosen prefab from a list at a specific location within a Tile.
  3. Global Prop: Ensures only a specific total number of a certain type of prop exists across the entire generated dungeon.

Recursive Props

Props are processed recursively, allowing you to have props that control other props. For example, you might have a "decoration" Random Prefab that spawns a random decorative object that could go on a table (e.g., a book, candle, or ornament). You could then have this prop be controlled by a Local Prop Set, that decides which of the "decoration" objects to keep.

Let's explore each one.


Local Prop Set

  • Purpose: To selectively keep a subset of GameObjects that are already placed within your Tile prefab. Ideal for over-decorating a room in the editor and then having DunGen randomly remove some items for variety.
  • Setup: Add the Local Prop Set component (Add Component > DunGen > Random Props > Local Prop Set) to a GameObject within your Tile prefab. The GameObjects you want this component to manage should be children of the GameObject holding the Local Prop Set component.

Inspector Settings:

  • Count Mode: Determines how the number of props to keep is decided:
    • Random: A random number between the Min and Max values of the Count range below will be chosen.
    • Depth Based: Uses the Depth Scale curve (see Prop Weights below). The X-axis (0-1) represents the normalized path depth, and the Y-axis (0-1) maps to the number of props kept (0 = Min Count, 1 = Max Count).
    • Depth Multiply: A random number between Min and Max is chosen (like Random mode), but this number is then multiplied by the value from the Depth Scale curve (Y-axis 0-1) at the current path depth.
  • Count (Min/Max): Defines the minimum and maximum number of child GameObjects that this component should keep active.
  • Prop Weights: This list holds references to the child GameObjects that the Local Prop Set manages.
    • Adding Props: Drag the child GameObjects from the Hierarchy into this list, or click "Add Selected Props" after selecting them in the Hierarchy.
    • Weight per Prop: Each prop entry has its own weight settings (Main Path, Branch Path, Depth Scale). When the component needs to decide which props to keep (if it needs to discard some to meet the count), props with a higher effective weight are more likely to be chosen. Refer to the Weighting page for details.

Outcome: When the Tile containing this component is placed, the Local Prop Set calculates how many of its child props to keep based on the Count Mode and Count range. It then selects which props to keep based on their weights and disables (discards) the rest.


Random Prefab

  • Purpose: To spawn a single prefab instance chosen randomly from a list you provide. Ideal for placing randomized decorations, containers, or interactive objects at specific points.
  • Setup: Add the Random Prefab component (Add Component > DunGen > Random Props > Random Prefab) to an empty GameObject within your Tile prefab. This empty GameObject acts as a marker for the spawn location and rotation.

Inspector Settings:

  • Zero Position: If checked, the chosen prefab will be spawned at the exact position of the marker GameObject, ignoring any positional offset the prefab itself might have relative to its own pivot. If unchecked, the prefab spawns at the marker's position, but offset by the prefab's own internal position (usually (0,0,0), but could be different).
  • Zero Rotation: If checked, the chosen prefab will be spawned with the exact rotation of the marker GameObject, ignoring the prefab's own base rotation. If unchecked, the prefab spawns with the marker's rotation plus the prefab's own base rotation.
  • Prefab Weights: This list holds references to the prefabs (from your Project view) that can be spawned by this component.
    • Adding Prefabs: Drag prefabs from your Project view onto the list.
    • Weight per Prefab: Each prefab entry has its own weight settings (Main Path, Branch Path, Depth Scale). The effective weight determines the likelihood of each prefab being chosen for instantiation. Refer to the Weighting page for details.

Outcome: When the Tile containing this marker is placed, the Random Prefab component selects one prefab from its list based on weights and instantiates it at the marker GameObject's position and rotation (potentially modified by the Zero Position/Rotation settings).


Global Props

  • Purpose: To control the total number of a specific category of object across the entire generated dungeon, regardless of how many potential instances exist within the placed Tiles. Useful for ensuring uniqueness (e.g., only one "Altar of Power") or controlling scarcity (e.g., between 1 and 3 "Treasure Chests").
  • Setup: Add the Global Prop component (Add Component > DunGen > Random Props > Global Prop) directly to the GameObject you want to manage within your Tile prefab (e.g., if you're wanting to limit the number of treasure chests, this should go on the treasure chest instance inside your tile).

Component Inspector Settings:

  • Group ID: A crucial integer identifier. All props that should be counted together must share the same Group ID. (e.g., all potential Treasure Chests might have Group ID 1, all Shrines might have Group ID 2).
  • Weights (Main Path, Branch Path, Depth Scale): These weights do not determine if the prop spawns initially (it's already part of the Tile). Instead, they act as a priority score. If DunGen places more potential Global Props of a specific Group ID than the allowed maximum (set in the Dungeon Flow, see below), it uses these weights to decide which instances to keep. Higher effective weight means higher priority to survive the culling process. Refer to the Weighting page for details.

Dungeon Flow Configuration:

The actual limit for each Global Prop category is set in your Dungeon Flow asset:

  1. Select your Dungeon Flow asset in the Project view.
  2. Find the Global Props section in the Inspector.
  3. Click the + button.
  4. Enter the Group ID that matches the Group ID you set on the components in your Tile prefabs.
  5. Set the Count (Min/Max) range. This tells DunGen the minimum and maximum number of props with this Group ID that should exist in the final generated dungeon.

Outcome: During the post-processing phase of generation, DunGen gathers all enabled GameObjects that have a Global Prop component. For each unique Group ID, it checks if the total count falls within the Min/Max range defined in the Dungeon Flow asset.

  • If there are too many props of a certain ID, it discards props at random based on the effective weight (priority) until the count reaches the maximum limit.
  • DunGen currently doesn't enforce the minimum count if too few potential props were placed initially.

Custom Prop Implementation

Custom prop behaviour can be achieved by creating a new component derived from the RandomProp abstract class. Simply implement the Process() method and DunGen will automatically call it when processing props.

public abstract class RandomProp : MonoBehaviour
{
    public abstract void Process(RandomStream randomStream, Tile tile, ref List<GameObject> spawnedObjects);
}
  • randomStream: The random number generator used to generate the dungeon. This ensures that the same dungeon will be generated again if an identical seed is used.
  • tile: The tile that this prop belongs to.
  • spawnedObjects: An list reference allowing us to let DunGen know if we spawned any objects of our own when processing the prop. This ensures that DunGen can properly process props recursively.

By strategically using these three prop components, you can dramatically increase the replayability and visual diversity of your dungeons without needing an excessive number of base Tile prefabs.