Skip to content

Advanced Features: Adjust Candidate Tiles

When DunGen is looking to spawn a new tile, it will first create a list of candidates pulled from the tile sets and archetypes assigned to the current section of the dungeon flow. Each candidate has a weight that is used to determine the likelihood of it being selected, relative to the other candidates.

In some cases, you may want to adjust this set of candidate tiles. Using custom code, candidates can be added/removed and have their weights adjusted to increase/decrease the likelihood of being selected. This can be done in one of two ways:


Option 1: Candidate Tile Rule

A custom rule can be added at runtime to DoorwayPairFinder.CandidateTileRules. Here's an example of a rule that increases the weight of any candidate tile with "Corridor" in its name by a factor of 10:

using DunGen;
using DunGen.TilePlacement;
using System.Collections.Generic;
using UnityEngine;

public class AdjustCandidateWeightsByName : MonoBehaviour
{
    public string NameFragment = "Corridor";
    public float WeightMultiplier = 10f;

    private CandidateTileRule rule;


    private void OnEnable()
    {
        rule = new CandidateTileRule(MutateCandidateTiles);
        DoorwayPairFinder.CandidateTileRules.Add(rule);
    }

    private void OnDisable()
    {
        DoorwayPairFinder.CandidateTileRules.Remove(rule);
        rule = null;
    }

    private void MutateCandidateTiles(PairingRequest request, ref List<CandidateTile> candidates)
    {
        foreach (var candidate in candidates)
        {
            if (candidate.TilePrefab.name.Contains(NameFragment))
                candidate.Weight *= WeightMultiplier;
        }
    }
}

Warning

The candidates list is pooled and should not be stored or modified outside of the scope of the MutateCandidateTiles method.


Option 2: Custom Generation Pipeline

Another way to adjust candidate tiles is to create and assign a new Generation Pipeline. Once created, you can make a custom class that implements ICandidateTileBuilder (or inherits from CandidateTileBuilder if you want to keep most of the default implementation).

This new class will then appear in the dropdown for the "Candidate Tile Builder" field in the inspector for your new generation pipeline asset.