Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

DunGen - Procedural Dungeon Generation

Discussion in 'Assets and Asset Store' started by Aegon-Games, Mar 7, 2014.

  1. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    DunGen 2.12.0 (Beta 2) is now available (See original post).

    NOTE: 2.12.0 beta 1 introduced some bugs in DunGen and the new sample that prevented a project from being built. These are now fixed in beta 2.
     
  2. Lokiare

    Lokiare

    Joined:
    Nov 2, 2014
    Posts:
    9
    Here's what I have:
    Screenshot 2019-11-17 14.14.39.png
    It says its DunGen 2.11.9 in the documentation. This is the latest version from the Unity store. Its still rotating or flipping the tiles. The tiles have the "allow rotation" unchecked.
     
  3. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    Strange, that definitely shouldn't be happening in 2.11.9. Nothing affecting tile rotation has been changed for 2.12.0 beta so the two versions should produce identical results.

    I'll do some more testing later today to see if I can figure out what's wrong. One thing I did notice from your screenshot is that your up vector is set to (0, 1, 0) whereas for top-down 2D, the up-vector would usually be (0, 0, -1). That shouldn't be causing the issue, but it's worth a try.
     
  4. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    For most of my tiles, I want to randomize the floor, as well as the walls.

    To do this I am planning on using the Local Prop Set. For example, Tile1 would have a Local Prop Set containing Walls1, Walls2, and Walls3. I would do the same for the floor. Tile1 would have a Local Prop Set, which would have Floor1, Floor2, and Floor3. Lastly, Tile1 would also have a Local Prop Set for the furniture.

    Since this is not how the feature is supposed to be used, I thought I better double check to make sure that I don't run into any issues.
    • Will this work fine, or do you recommend a different way?
    • Is there a limit to the amount of local prop sets that can be used within each tile?
    Capture.PNG
     
    Last edited: Nov 18, 2019
  5. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    Could some of your doorways be upside-down? That's the only thing I can think of that might cause that issue. You should be able to quickly check if this is the case by selecting your dungeon flow asset and clicking the "Validate Dungeon" button at the top of the inspector.


    Using any of the prop types on the walls & floors should work fine. There's no limit to the number of local prop sets that can be used in each tile.

    One thing to note is that putting doorways inside a prop set would cause problems since the tiles are connected by their doorways first, then the prop sets are evaluated later - it might destroy a doorway that was in use.
     
    LumoKvin likes this.
  6. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    Related to my previous question, if I have a lot of props, should I use Random Prefab or Local Prop Set for performance and fast load time?

    I assume that Local Prop Set is more expensive, because all the unused objects would be destroyed. Is that correct?
     
  7. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    Unfortunately, I don't really have a solid answer for this - there are different performance considerations for each option.

    - Local Prop Set: destroys unused objects and has the additional overhead of having more objects in the tile to begin with.
    - Random Prefab: has to instantiate a new prefab instance

    But prop placement shouldn't take much CPU time compared to the other tasks DunGen has to do and there's a good chance the performance difference between the two options is negligible anyway.

    Personally, I'd just go with whichever option works best for now.
     
  8. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    I have just updated to the latest version and I really like the Dungeon Crawler sample included with the update. Great job on that. I have ran into a issue with using Dungen and Opsive UCC together. My character isn't able to move through the doorway. I believe it's a collision issue between the UCC player and Dungen. Any ideas about this?
     
  9. Gabriel_SG

    Gabriel_SG

    Joined:
    Apr 7, 2017
    Posts:
    193
    I've had something similar, if it's the same issue i had then it's an Nvidia PhysX physics bug. Update to the newest version of unity to resolve it.
     
  10. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    I'm currently using Unity 2019.2.4f1 so I need to update farther?
     
  11. Gabriel_SG

    Gabriel_SG

    Joined:
    Apr 7, 2017
    Posts:
    193
    May not solve your problem but try it if you like...

    upload_2019-11-25_0-53-52.png
     
  12. Lokiare

    Lokiare

    Joined:
    Nov 2, 2014
    Posts:
    9
    How would I change the up vector? Should I just rotate everything or is there a setting in Unity to set this?
     
  13. Lokiare

    Lokiare

    Joined:
    Nov 2, 2014
    Posts:
    9
    When I do this, it says my 3rd door has the wrong up vector, but it has the same up vector as the other 3 doors.
     
  14. Lokiare

    Lokiare

    Joined:
    Nov 2, 2014
    Posts:
    9
    Never mind I swapped from 2d to 3d and looked around and the door was upside down on the other side of the map. Now everything works fine.
     
  15. Feartheway

    Feartheway

    Joined:
    Dec 12, 2017
    Posts:
    46
    Okay, i have worked through the tutorial and made a pretty cool dungeon. I put a first person controller in from standard assets and i can run around but when i hit a doorway i hit an invisible wall. I disabled the box collider on the door but still having problems running through doorways? any advice?
     
  16. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    You should be able to find what's blocking the character using Unity's physics debugger (Window > Analysis > Physics Debugger). Make sure you're in the scene view with gizmos turned on and "Collision Geometry" checked.

    PhysicsDebug.png
    By default, DunGen puts a box collider around each room, but this is a trigger (displayed in yellow in the physics debug view) so it won't block the character.
     
    camta005 likes this.
  17. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    Some character controllers treat colliders differently. Can you try without the controller to see if that is the issue?

    This probably isn't the issue, but make sure that the doorways are lined up properly. The pivot point of the door must match the pivot point of the DunGen doorway. I had a problem with this in the beginning because the door's pivot was on the bottom left, but the DunGen doorway pivot is in the middle at the bottom. There might be a wall from another room blocking the doorway. If your walls are planes, then they only render from one side, which would make it look like there is nothing blocking.

    After the dungeon is generated, you can switch to scene view to analyse the dungeon while in play mode.
     
    Last edited: Nov 27, 2019
  18. verteom

    verteom

    Joined:
    Oct 26, 2018
    Posts:
    38
    Hi ,I just bought the Dungen Asset, I imported the asset, that demo seems so cool~ But I try to figure it out about, I need to put my monster into prefab before when generate the dungeon ? Because I find the mini boss node and boss node, is it that means I also need to put the monster before generate?
     
  19. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    Yes, you would put monsters into your room prefabs. Or if you wanted to make a custom script to spawn monsters, that would be placed inside your rooms instead.
     
  20. verteom

    verteom

    Joined:
    Oct 26, 2018
    Posts:
    38
    Ťhanks~Another question ,is must have goal in the end node? Can you help me how to connect the dungeon to another dungeon? I tried to set two Dungeon and found two dungeon can set portal to transform player to each other. But in one dungeon, should I set portal in the GoalRoom , when player trigger enter the portal, and generate another agian?
     
  21. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    That's how we did it in the dungeon crawler sample. We put a portal in the goal room; when the player clicks on the portal, we generate a new dungeon and teleport the player to the start of the new dungeon.
     
  22. verteom

    verteom

    Joined:
    Oct 26, 2018
    Posts:
    38
    I found it~ Thanks a lot~
     
  23. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    In the example, Awake() is used instead of Start(). Does it matter which one I use?

    I read somewhere that it is safer to use Start() when you need to access another object's properties. For example, if I want to change a TextMeshPro object right after the dungeon is generated, then it is safer to use Start(). Is that correct?
     
    Last edited: Dec 2, 2019
  24. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    48
    in your example, after reaching the portal, the next generated dungeon has wrong navmesh (it keeps the previous one instead of baking the new one)
    Also, is it possible that navmesh is not pink (no material)? its affecting the reflection when minimap is active.
     
  25. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    I use Awake() in the example instead of Start() because if "Generate on Start" is checked on the runtime dungeon component, it's possible that the dungeon is generated before we start listening for the completion event. This is based on script execution order which can be changed from 'Edit > Project Settings... > Script Execution Order', but I prefer not to have to mess with that.

    As far as I know, accessing another object's properties in Awake() should be perfectly safe as long as the property is initialised by then. For the runtime dungeon component, I know I initialise the 'Generator' property inline with the declaration, so it should be fully initialised during the constructor (before even Awake() is called). You just need to know that the value of the property is going to have been set before you access it - so if you don't know when a script does that, accessing it from Start() is probably safest.


    The navmesh is being re-baked properly for me. Are you getting any errors in the console?

    I'm rendering the navmesh to the 'Water' layer by default (we couldn't add custom layers and still include the sample in DunGen so I just used the existing ones). Is it possible to cull specific layers using whichever reflection solution you're using? If you're using the built-in reflection probes, you can un-check 'Water' from the Culling Mask.
     
  26. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    Hello,

    Is it possible for DunGen to handle this situation?:

    In my game, I have several puzzles the player must solve to move on to the next section. Like in order to get from section 1 to section 2, the player needs to turn on a generator that powers the door that leads to section 2. This generator will be in a different room. This will be randomized meaning the puzzles can be different. One scenario can be the door needing a generator to be turned on, another can be needing to find a key card, and so on.

    If I were to make this completely random it may be possible for the player to get stuck because it might spawn a door that needs key card, but the room with the key card didn't spawn because DunGen chose a different tile instead of the one needed for the solution to the puzzle. Is it possible to make certain tiles appear depending on the puzzles that spawn?

    The boss room will also be more complex in that it will have multiple puzzles requiring the player to backtrack, such as to find a room containing a note with a password on it, finding a room that contains a spark plug, etc. In the complete version, this game will have 2 sections plus a boss room with a puzzle for each. So it's 3 puzzles and it should be randomized which 3 it picks, but I need to make sure that the correct objects needed to solve each puzzle also spawn somewhere in the dungeon.

    I was thinking I can do this by making a separate Dungeon Flow for each scenario, picking a random one, and then plugging that into the DungeonGenerator, but there are too many different combinations for that and was wondering if there's a better way. If this is the only way, how can I put in a random Dungeon Flow into the Dungeon Generator at runtime?
     
  27. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,114
    If I am understanding it right, it sounds like this would be fairly simple. You'd use the lock and key feature for all of these puzzles. This feature would ensure that all of your keys are placed in the dungeon layout before their locks.

    So the generator would be placed before the locked door. And the note with the password would be placed before the boss room.

    How you would handle the note idea is the note could be rendered but with an inactive trigger the first time the player passes through the dungeon. However, once they enter the boss room (final room), the player clicks something or trips a trigger which in turn enables a trigger on the note object. So now, when the player backtracks and finds the note, they can interact with it.

    I don't think you'd have to do anything funny with the dungeon flow. If I'm understanding your needs correctly, just use the lock and key mechanism.
     
    Aegon-Games likes this.
  28. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    I hadn't thought about using the lock and key system. I think that can work for the more simple puzzles where you just grab a key to unlock a door, but some puzzles are more complex, such as the ones in the boss room. The ones in the boss room can require multiple steps, or even have multiple puzzles. Like it can be a garage where you have to turn on a generator to open the door, but there is also a car in it with parts missing, such as a spark plug, battery, and a tire. These items can be found in the previous sections, but I need to make sure that they are spawned if this boss room puzzle is the car puzzle and not some other puzzle that was randomly chosen.

    The boss room puzzles are fixed, in that each boss room is specifically designed for a specific puzzle. I have multiple boss rooms built and have DunGen randomly select one per level. So I'm trying to find a way to make sure that if a specific boss room is chosen, the objects needed for those specific puzzles are spawned somewhere in the dungeon.
     
  29. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,114
    One way to address this is to have a different dungeon creation routine for each different type of puzzle. This way you control which keys are used and which boss room is deployed, and only the layout is random. You then use your own random routine to select which puzzle will appear.

    Or you can use a generic boss room, with generic keys, and decide the puzzle type after the dungeon is generated. You'll have empty game object keys A, B, and C already placed, and you assign a prefab or components to them once the puzzle is decided, giving them meshes, triggers, and whatever other else you need.
     
  30. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    By dungeon creation routine, do you mean dungeon flow? Is there a way I can have the runtime dungeon generator randomly pick a dungeon flow? Currently, I can only put in one dungeon flow into the Runtime Dungeon script.
     
  31. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,114
    What I was meaning is that if your puzzle design is based upon specific boss rooms, you can do a separate dungeon flow for each puzzle type. That way you get the boss room you are calling for, plus the keys specific to that puzzle type.

    When your game is in play mode, it generates a random number and selects the puzzle associated with that number.

    So, when you randomly decide to use puzzle #2, you make the random dungeon with that particular boss room and keys.
     
  32. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    The problem is the Runtime Dungeon component only takes in one Dungeon Flow. I'm guessing I would need to uncheck the "Generate on Start" option, use my own script to randomly pick a Dungeon Flow and plug it into the Runtime Dungeon component, then start the dungeon generator manually? Or is there a way to make the Runtime Dungeon component take more than one Dungeon Flow and automatically select a random one?
     
  33. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,114
    There's all kinds of ways to do it, I suppose. The best approach is usually to do some basic experimentation and see what works and how easy it is to do it.

    I'd suggest beginning with setting up a single simple puzzle dungeon, with a lock and key. Something really simple, because you're prototyping.

    Then set up a second, different puzzle dungeon, maybe simply by changing the color of the boss room. Figure out how to switch between the two dungeons, generating and destroying the dungeon on command, and randomly changing the seeds for the dungeons, so you can get different looks for the same puzzles.

    Then begin creating your different puzzle mechanisms as simple prototypes and implementing them as separate dungeons that you can switch to. Name them after each new puzzle mechanism.

    My philosophy is to always try the simplest things first, and do them one at a time. See where that leads you.
     
  34. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    Oh, I have the actual dungeon working already, I'm just trying to figure out how to access the Dungeon Generator through code so at runtime I can tell it what Dungeon Flow I want to use and to generate the dungeon. There doesn't seem to be anything about that in the documentation.

    EDIT: I figured it out after looking at the code in some of the sample scripts. Thanks for all the help.
     
    Last edited: Dec 6, 2019
    hopeful likes this.
  35. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    48
    Did you play your example scene and actually get to the end? I have done it in 2 computers and the second dungeon has wrong navmesh (it has the first generated one)

    Also, this generated naves is showing up in pink (no material)
     
  36. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    As I said, it works fine for me.


    Are you getting any errors in the console?

    The rendered navmesh is supposed to not have a material, it doesn't need one to work properly since the shader that renders the minimap works as long as the pixel's red-channel is non-zero.
     
  37. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    352
    Hello are you planning to support none linear flow for dungeon? I mean flow with several branches an cycles?
     
  38. CF-Games

    CF-Games

    Joined:
    Jun 2, 2013
    Posts:
    128
    For the dungeon flow, I have it split up into several segments with several different Dungeon Archetypes for each segment. Sometimes when the dungeon is generated, the same archetype is used in more than one segment. Is there a way to limit it so that each archetype can only be used once in the dungeon flow?
     
  39. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    That's something I'd love to add and something I've been thinking about for a few years now. Unfortunately, with the way DunGen currently works, I can't figure out a way to make looping paths possible without adding constraints to rooms creation.

    The problem is that since DunGen places rooms one at a time and they can be any size or shape, there's no easy way to find a valid set of rooms that will line up perfectly to bridge the gap (there's not even a way to guarantee that it will be possible).


    There isn't currently a way to do this. I'll see if it can be added in the next version.
     
  40. pleska

    pleska

    Joined:
    Mar 23, 2014
    Posts:
    1
    I haven't seen this reported yet. But I seem to have connector doors being generated away from the rooms in DunGen 2.12 with Unity 2019.2.14f1. Now I am not 100% sure if this is Multistory Dungeons or DunGen problem, but with the little bit of debugging it seems to be DunGen or something that changed. Anyone have any ideas?

     
  41. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    352
    Hope you will figure that out someday.
     
  42. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    In the demo scene, you call Generate() when the player presses R. Also, in the Runtime Dungeon script, you call Generate() from the Start method.
    Code (CSharp):
    1. DungeonGenerator.Generate();
    When the player reaches the end tile, I want to teleport the player back to the start tile, and then call Generate() to create a new layout. I think this would be faster than reloading the scene.
    Is this a good way to do this?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DunGen;
    5. using DunGen.Adapters;
    6.  
    7. public class DunGenRegenerator : MonoBehaviour
    8. {
    9.     private RuntimeDungeon generator;
    10.  
    11.     void Start()
    12.     {
    13.         generator = GameObject.FindGameObjectWithTag("Generator").GetComponent<RuntimeDungeon>();
    14.     }
    15.  
    16.     public void Regenerate ()
    17.     {
    18.         generator.Generate();
    19.     }
    20. }
    21.  
     

    Attached Files:

    Last edited: Dec 9, 2019
  43. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    48
    How to change the default navmeshSurface settings that the generator is attaching to root?
     
  44. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    From now on I'm going to try to stick to patch versions being bug fixes only (version number is major.minor.patch, so this is 2.12, patch 1). These bugfix versions won't contain new features and won't really be going into beta like I've done in the past. I'll be pushing them to the asset store immediately, but a download link will be provided if anyone needs it before it gets approved by Unity.

    Version 2.12.1 - Available on the Asset Store
    Available on the Asset Store as of 12 December 2019

    • Dungeon generator settings should now properly work with the new prefab workflow in Unity
    • Fixed an issue causing the phase of a post-process step to be ignored
    • Connector prefab instances now correctly have their local position reset after being parented to the doorway


    As of 2.12 connectors are parented to their doorways, rather than being parented to the dungeon root. As a result, the placed prefab instances keep their position/rotation/scaling. The connector prefabs in that pack have an offset of (87, 0, 6) so they are placed in the wrong position now.

    I've changed that behaviour in 2.12.1 so it resets the transform of a prefab instance after it is placed since having an offset on the prefab itself is usually unintentional. You can also just set the connector prefabs' position to (0, 0, 0) instead.


    That should work fine. Reloading the scene might not be as slow as you think though if you'd prefer to do it that way.


    Unfortunately, that can't be done right now. I'll look into adding that functionality for the next version.
     
    Last edited: Dec 13, 2019
    camta005, hopeful and Vincent13122 like this.
  45. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    I'm using Unity 2019.2.4f1 and DunGen 2.12.0. I'm following the readme guide and I'm trying to integrate the Unity NavMesh. I noticed there is no “Unity NavMesh.unitypackage” in “Assets/DunGen/Integration”. Did I miss something?

    Edit: No bad. After looking at the Dungeon Crawler readme and realizing that the dungeon generator was a child and not a parent. I managed to get the NavMesh to generate without the other dependency.
     
    Last edited: Dec 15, 2019
  46. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    The global override settings are grayed out. How can I change these settings?

    upload_2019-12-15_12-3-42.png
     
  47. gearedgeek

    gearedgeek

    Joined:
    Jun 19, 2015
    Posts:
    177
    You should be able to click on the check box to enable them. I was able to Enable "Allow Tile Rotation".
     
    Aegon-Games likes this.
  48. LumoKvin

    LumoKvin

    Joined:
    Sep 28, 2019
    Posts:
    195
    Thanks. I will try it tomorrow. If it works, I will feel very stupid.
     
  49. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    170
    What does it mean "Tiles in an archetype should have more than 1 doorway"?

    I have some rooms I only want to have one doorway, and they would terminate a branch path.
     
  50. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    455
    Tiles with only one doorway are allowed, but they should be in their own TileSet and should only be used for branch caps or the start/goal room. The warning is saying that you have some single-doorway tiles assigned to an archetype (a line segment on the graph) and that they won't be used.
     
unityunity