DunGen - Procedural Dungeon Generation

If I generate a new Dungeon from editor (with New Dungeon window) is there a way to know the key required from a door?

Because in RunTime is quite easy via

public void OnKeyAssigned(Key key, KeyManager manager)

but how can I do something like that for a specific door when the dungeon is already created?

The OnKeyAssigned function will still be called when the dungeon is generated from the editor, so you should be able to cache the key into a serialized field or property so it can be accessed later. Something like this:

public class LockedDoor : MonoBehaviour, IKeyLock
{
    [SerializeField]
    private int keyID;

    [SerializeField]
    private KeyManager keyManager;


    public void OnKeyAssigned(Key key, KeyManager manager)
    {
        keyID = key.ID;
        keyManager = manager;
    }

    private void Start()
    {
        if (keyManager == null)
            return;

        // Get the key from the key manager
        var key = keyManager.GetKeyByID(keyID);
    }
}

Now you can use the cached keyID to get the key from the KeyManager at runtime (like Iā€™m doing here in the Start function) to do whatever you need to do with it.

1 Like

Amazing another issue solved :grin::+1:
I wonder if could use a prefab set as Blocker in a doorway with Prop Local Spawner with an array element a Key Spawnerā€¦ Have you tested it? :thinking: :grin:

I havenā€™t tested that yet, but the order that these things are processed in the code goes doorways > props > locks & keys, so I think what youā€™ve written should work.

1 Like

Hi, I get the following error when I try to generate it in the Generate Dungeon Window on the editor.

MissingReferenceException: The object of type ā€˜RandomPrefabā€™ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
DunGen.RandomPrefab.Process (DunGen.RandomStream randomStream, DunGen.Tile tile) (at Assets/DunGen/Code/RandomPrefab.cs:27)
DunGen.DungeonGenerator.ProcessLocalProps () (at Assets/DunGen/Code/DungeonGenerator.cs:1207)
DunGen.DungeonGenerator+d__131.MoveNext () (at Assets/DunGen/Code/DungeonGenerator.cs:1144)
DunGen.DungeonGenerator.Wait (System.Collections.IEnumerator routine) (at Assets/DunGen/Code/DungeonGenerator.cs:257)
DunGen.DungeonGenerator+d__111.MoveNext () (at Assets/DunGen/Code/DungeonGenerator.cs:367)
DunGen.DungeonGenerator.Wait (System.Collections.IEnumerator routine) (at Assets/DunGen/Code/DungeonGenerator.cs:257)
DunGen.DungeonGenerator+d__108.MoveNext () (at Assets/DunGen/Code/DungeonGenerator.cs:246)
DunGen.DungeonGenerator.Wait (System.Collections.IEnumerator routine) (at Assets/DunGen/Code/DungeonGenerator.cs:257)
DunGen.DungeonGenerator.Generate () (at Assets/DunGen/Code/DungeonGenerator.cs:190)
DunGen.Editor.DungeonGeneratorWindow.GenerateDungeon () (at Assets/DunGen/Code/Editor/Windows/DungeonGeneratorWindow.cs:58)
DunGen.Editor.DungeonGeneratorWindow.OnGUI () (at Assets/DunGen/Code/Editor/Windows/DungeonGeneratorWindow.cs:28)

It appears that generator is accessing a RandomPrefab that was deleted in the LocalPropSet draw. For unknown reason, this does not occur while in playback mode.

Iā€™m loving this asset so far - the only thing Iā€™ve been scratching my head on is trying to make sure the start room uses more than one doorway. Basically, the main path generates, and the branches branch of off it (and other branches). This leads to other doorways in the start room being unused, where Iā€™d like them to be used. Is this possible? To get branches to start from the main roomā€™s extra doorways? Or, is it simply relying on RNG to loop back to the start? Iā€™d be willing to modify the generator if thatā€™s what it takes, but I figured Iā€™d ask first to see if thereā€™s any out-of-the-box solution.

Thanks for letting me know. Iā€™ve fixed the issue and the new update should now be available on the Asset Store.

1 Like

Branches are currently only supported on the connections between nodes in the dungeon flow graph, not on the nodes themselves (including the start and goal tiles).

Unfortunately, modifying that behaviour would be a fairly involved process since the branch settings are all in the Archetype class. Iā€™ll need to find some time to look into it properly and see what it would take to support branches everywhere. I feel there was a reason I didnā€™t allow branches from graph nodes, but itā€™s been so long I donā€™t know what it was or if the reason is even relevant any more.

Hello, I am getting these errors after importing Dungen, A* Pathfinding Project and the Adapter:

Assets\DunGen\Integration\AStarPathfindingProjectPro\AStarNavMeshAdapter.cs(70,50): error CS1061: ā€˜Progressā€™ does not contain a definition for ā€˜descriptionā€™ and no accessible extension method ā€˜descriptionā€™ accepting a first argument of type ā€˜Progressā€™ could be found (are you missing a using directive or an assembly reference?)

Assets\DunGen\Integration\AStarPathfindingProjectPro\AStarNavMeshAdapter.cs(90,26): error CS0029: Cannot implicitly convert type ā€˜intā€™ to ā€˜Pathfinding.PathfindingTagā€™

I didnā€™t notice there was a big update to A* Pathfinding Project Pro earlier this year so my adapter was out of date.

Iā€™ve updated the adapter to work with 5.0+ and the change should be available on the Asset Store now.

1 Like