Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

DunGen - Procedural Dungeon Generation

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

  1. Creiz

    Creiz

    Joined:
    Jun 6, 2017
    Posts:
    105
    I'm having a bit of a stiffy with this. Nothing too bad, I hope.

    I'm trying to make a 3 way tile, for corridors. I need Dungen to make a bunch of rooms, (like 5~10 of them), separated fairly far, then connect these with corridors. And this where I'm stuck.

    So I have my corridor I and L which works correctly. However, I need some corridors to branch out. So I made a T tile with 3 doorways but sometimes it doesn't use 1 or 2 of those doorways. How can I force it to use all of them?

    Also, I need the corridors to lead to a room. Sometimes it doesn't a just cuts short. Can I also force it?
     
  2. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Sorry for the late reply, I've been out of commission since Wednesday.

    Unfortunately, it's not possible to guarantee all of the doorways of any given tile will be used.

    For branches ending in a corridor, the 2.15 beta has a new option in the dungeon flow asset settings that will delete the last tile in each branch if it doesn't meet the requirements you specify (it does this recursively so it will prune the branch until there's a valid cap tile).

    This can be used to make sure there are no corridors on the end of a branch. Here's how you'd do it:

    1. Create a tag called 'Corridor' (Window > DunGen > Tags)
    2. For each of your corridor tile prefabs, if it doesn't have a Tile component, add one. In the tile component, add your new 'Corridor' tag to the list of tags at the bottom of the inspector.
    3. In your dungeon flow settings, set the 'Branch Prune Mode' to 'Any Tags Present', and add your corridor tag to the list below.
     
  3. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    289
    Question regarding nodes in the dungeon flow.
    I have a dungeon flow with two different tile sets.
    A main dungeon tile set and a sewer tile set.
    I have my flow(picture attached) starting with the main dungeon TS segment, then I have a node to transition to the sewer TS segment.
    Then towards the end i have another node to transition back to the original main dungeon TS segment.
    The problem is when I run it I only get 3 sewer tiles. How do I make DunGen produce more tiles for that segment?
    upload_2021-10-19_13-33-48.png
    upload_2021-10-19_14-8-33.png
    upload_2021-10-19_14-7-52.png
     
  4. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    The number of rooms generated for a line segment is based on the relative length of the line and the dungeon flow's 'Length' property. For example, if you have a dungeon flow with a length of 15 rooms, and it has 3 line segments of equal length, each segment would produce 5 tiles.

    So there are two ways to increase the number of tiles in a segment:
    1. Make the line segment longer relative to the other line segments in the flow graph.
    2. Increase the number of rooms in the dungeon as a whole by increasing the 'Length' property in the dungeon flow.
     
  5. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    20
    How can I reposition your NavMesh it is offset to the tiles ? The NavMesh is perfect it is just below the tiles.
    How is the NavMesh location in relation to the tiles decided ?
    Can I alter the code somewhre to set the starting position ?
    Thanks !
     
    Last edited: Oct 25, 2021
  6. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Are you using the Unity navmesh adapter? If so, Unity handles generating the navmesh and as far as I know there's no way for us to give it a height offset. If the navmesh is only below the floor by a small amount it might not be a problem at all - you should just be able to decrease the 'Base Offset' in the NavMeshAgent component.
     
  7. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    20
    I am using your NavMesh adapter. The NavMesh is offset to far, I have to locate the tiles in different locations because of the way the Multiple scenes are located and the is also a MMORPG networked game so the dungen can be placed in multiple locations. Its seems to be offset by the distance the spawntile is set from 0,0,0
     
  8. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    There are three navmesh adapters in DunGen: One for Unity's own navmesh using their navmesh components package, and another two for the 3rd party assets A* Pathfinding Project Pro and RAIN (asset now deprecated). I assume you're using the one for Unity's own navmesh system.

    The only scenario I can think of that would cause the navmesh to be offset from the dungeon is if the dungeon was moved after it finished generating, and your navmesh adapter uses 'Full Dungeon Bake' as the bake mode with 'Auto-Generate Surfaces' turned off. In that situation, your dungeon could be separate from the NavMeshSurface component and you'd need to be sure to move them both the same amount.
     
  9. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    20
    Awesome thanks for the help ! I will check that out. You were right thanks !!
     
    Last edited: Oct 28, 2021
  10. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    20
    What layers does the NavMesh adapter ignore or where can I change it ? Layer "Ignore Raycast" also gets NavMesh. It looks like you have addressed this in DungeonCrawlerNavMeshAdapter. I just added a layermask to the script works great.
     
    Last edited: Oct 30, 2021
  11. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    34
    Setting a Lock for Injected Tile is nice.
    However, is it possible to select the position of the lock?
    I used it for blocking the main path, but the lock did not necessarily spawn on the main path.

    I want to use a room with 3 or more doors and set a lock gate only on the door that goes through the main path.
     
  12. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    34
    Sorry to bother you again.
    I'm using GlobalCountMode, and I was wondering why branches were prioritizing the second half of the dungeon to be generated.

    The problem seems to be that the random number used in line 84 of BranchCountModes.cs is Integer. randomStream.NextDouble() seems to have improved the situation.
     
  13. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    20
    When using the UnityAdapter for creating NavMesh it is making gaps where the tiles connect. Is there a way to correct this ?
    I tried using the DungeonCrawlerAdapter which fixed that issue but picks up all objects everywhere not just under the root folder.
    Any advise would be great, thanks.
     
  14. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    I've just pushed a new bugfix version (2.15.1) to the asset store, it should be available immediately.

    the new asset store version (2.15.1) allows you to choose which layers to include whenever DunGen has to make a new NavMeshSurface. Any existing NavMeshSurface component will use their own layer mask still.


    Locks on injected tiles were always supposed to appear on the entrance to the tile, but there was a bug that sometimes allowed it to be placed elsewhere. I've just fixed this issue in the new asset store version (2.15.1). I'd like to re-work the way locks are places so users have more control over where they are allowed to go, but that's going to have to come in a future version.

    Thanks for letting me know about the global count mode issue, I've fixed that in the new asset store version too.

    The DungeonCrawlerNavMeshAdapter shouldn't include objects outside the dungeon root, so I'm not sure why that's happening, I wasn't able to reproduce the issue. About the gaps between tiles, there are two things I can think of that might cause it:
    1. There's actually a small gap between your tiles, but it's big enough that the navmesh thinks they're not connected
    2. If you tiles are connected by doorways, your agent radius might be too big to fit through the doorway. Open the Navigation window (Window > AI > Navigation), select your agent(s) from the list and try lowing the 'Radius' property.
     
  15. ok8596

    ok8596

    Joined:
    Feb 21, 2014
    Posts:
    34
    Sorry for repeating myself.
    In some cases, branchesRemaining in ComputeBranchCountsGlobal() is a negative value, in which case the number of branches seems to be higher than expected.
     
  16. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    You're right, looks like I wasn't clamping that properly - thanks for letting me know. I just pushed an update to the asset store. It's the same version number (2.15.1) but you should still be able to update the package.
     
  17. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    154
    I know it says Unity 2019, but any chance you have 2017.4.37f1 Build, if so, I will buy it
     
  18. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    The current asset store version works for Unity 2017. Up until a few versions ago I was actually publishing from 2017.1, so I haven't been using any features that depend on newer versions. The dungeon crawler sample project does require Unity 2019+ though.

    I can't guarantee that future versions of the asset will continue to work in older Unity versions, but I'll try to avoid braking compatibility if I don't have to.
     
  19. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    154
    I bought it, I will let you know when I use it. It will be soon .
     
    Last edited: Nov 18, 2021
  20. ZaharAlone

    ZaharAlone

    Joined:
    Mar 14, 2018
    Posts:
    3
    Hi!

    Faced such a problem that in my dungeon, the room is generated above the room. Yes, I have a vertical drop. But I need to avoid generating a room above the room, can I somehow do this using standard means DunGen?
    изображение_2021-11-16_224936.png изображение_2021-11-16_224944.png
     
  21. JamesKalin

    JamesKalin

    Joined:
    Aug 27, 2014
    Posts:
    2
    Hi there. Just bought DunGen. I understand DunGen can be used to procedurally generate towns. Can anyone point me at any doc or examples of DunGen being used to do this? I'm excited to dive into the product.
    Jim
     
  22. adamz

    adamz

    Joined:
    Jul 18, 2007
    Posts:
    1,163
    Does anyone know how the lightning deal works? Does the percentage off reduce as more people buy an asset? I ask because DunGen said it was -90% before the time was up, but now it's -70%. So I'm confused as to how it works.
     
  23. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    You should be able to avoid that by checking the 'Disallow Overhangs' box in the inspector of the Runtime Dungeon component.


    I've never used DunGen to generate a town before, but the way I'd going about doing this would be to make my tiles as square chunks containing some roads and buildings. I'd place doorways on each edge of the tile where I want them to connect. Something like this image (top-down view):

    DunGenTownChunkTile.png

    Red Border = The tile boundaries
    Blue Lines = Doorways
    Grey = Roads
    Brown = Buildings

    You'd probably need to make use of 'Connectors' and 'Blockers' on the doorway components (objects that are added/removed based on whether a doorway is used or not) to block-off areas outside the level bounds. I did something similar for the graveyard tiles in the included dungeon crawler sample.


    Yeah, it's strange that Unity doesn't seem to explain this anywhere. Here's how it works:

    Lightning deal assets have a limited number of licenses available at each price point. The asset starts with 20 licenses at 90% discount. Once those are all bought, there are 50 licenses at 80% discount, and finally 400 licenses at 70% discount. Once all licenses are purchased, the asset falls back to the standard 50% discount for the remainder of the sale.

    If you go to bottom of the list on the lightning deal page, you'll see some assets that haven't started yet and they'll have a countdown for when they'll be on sale starting at 90% off.
     
    adamz likes this.
  24. JamesKalin

    JamesKalin

    Joined:
    Aug 27, 2014
    Posts:
    2
    Your description of how to use DunGen to makes towns looks straightforward to try out. I can imagine various ways I might implement this solution.
    Much thanks, Aegon-Games person.
     
  25. JohnGrizzly

    JohnGrizzly

    Joined:
    Oct 27, 2021
    Posts:
    2
    Hello,

    I'm considering buying the DunGen but first I wanted to know if it's possible to make a fully linear structure with different sized rooms. The goal would be to have a kind of train shape but with different sized rooms procedurally placed inside.
    Just need to know if it's possible then I'll figure it out^^
     
  26. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Yes, that's possible. DunGen just uses whatever room prefabs you give it, the only restriction is that doors need to be on the boundaries of the room and need to be axis-aligned. If you only put doorways on the two opposite ends of a room, you'll always get a straight line layout as a result.
     
  27. JohnGrizzly

    JohnGrizzly

    Joined:
    Oct 27, 2021
    Posts:
    2
    Perfect, thank you so much !
     
  28. ramtamir

    ramtamir

    Joined:
    Feb 23, 2019
    Posts:
    17
    Trying to get navmesh working. I'm getting a bunch of errors all regarding navmeshsurface not existing. How do I solve this?
     
  29. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    NavMeshSurface is part of Unity's newer navigation package which still has to be downloaded separately for some reason. You can find it on the github page (scroll down to the 'How To Get Started' section for instructions on how to add it to your project).
     
  30. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    122
    Hello, I don't have this asset atm but I had a question. How does it auto connect rooms using doorways, does it check if any of the parts of the rooms collide with each other, or do you have to specify some kind of tiling for each room?
     
  31. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Yes, it checks for collisions between the room prefabs. At the moment I'm using an axis-aligned bounding box for checking collisions, so the doorways need to be on the edge of that box to work properly, but the size/shape of the rooms can be what ever you want as long as the doors are on the edge of the bounding box.
     
  32. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    122
    Cool thanks for the info.
     
  33. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    122
    Hey just had another question, is this mainly just for indoor stuff? is there any way to do outdoor stuff and maybe have like background tiles spawned around the main tiles to populate stuff like for example buildings or trees that are basically just background tiles that have no doors and are just used as decoration ?
     
  34. NotQuiteSmith

    NotQuiteSmith

    Joined:
    Oct 27, 2013
    Posts:
    91
    I implemented OnTileChanged but there's an issue if a player moves forward into a new tile - by a small amount - and then backs out. The event fires when moving forward, reporting the previousTile and newTile, but it does not fire again as the player moves backwards.

    I suspect it's because the player's collider never fully leaves the "previous" room and so doesn't trigger an "entry" event when moving backwards.

    I'd like to track which room the player is currently in, but using this event would give me the wrong room :-(.

    I could probably put the DungenCharacter script on a child object that has a very small box collider that's much less likely to occupy the space across two room colliders? Then rebroadcast the event, etc.

    Just wanted to check if there's a better option and that I'm using this correctly.
     
    Last edited: Dec 2, 2021
  35. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    I'd originally intended DunGen to be just for interiors, but there aren't any restrictions preventing it from being used for outdoor scenes - tiles can be pretty much whatever you want. The included dungeon crawler sample has an outdoor biome that just works the same way as indoor tiles, but the entire length of the tile edge is used as a doorway.

    There's no built-in way to decorate scenes with background objects though. What it means to fill in the surrounding area is going to depend on the type of game being made as well as the size and shape of the tiles used.


    Your suspicion was correct, the issue was that the entry event of the original room wasn't being called when moving back into it since the character had technically never left.

    I've just modified the way the character component works, so now it should properly handle this edge case. The new build should be up on the asset store right now (same version number, but you should still be given the option to update).
     
    NotQuiteSmith likes this.
  36. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Hiya, is there a way to get the center Vector3 coordonate of a dungeon once it is generated? I am trying to instantiate a grid of the size of the dungeon at the right position. Is there an api call for that?

    Thanks,
    -Jeff
     
  37. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    The Dungeon class has a Bounds property you could use. A reference to the current dungeon can be obtained from the generator once it's completed:

    Code (CSharp):
    1.  
    2. public RuntimeDungeon RuntimeDungeon;
    3.  
    4. private void Start()
    5. {
    6.     RuntimeDungeon.Generator.OnGenerationStatusChanged += OnDungeonGenerationStatusChanged;
    7. }
    8.  
    9. private void OnDungeonGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status)
    10. {
    11.     if (status != GenerationStatus.Complete)
    12.         return;
    13.  
    14.     var bounds = generator.CurrentDungeon.Bounds;
    15.     // Do something with the bounds
    16. }
     
  38. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Thanks! That worked like a charm.
     
  39. juglarx

    juglarx

    Joined:
    Dec 27, 2014
    Posts:
    60
    Hi All it's works on 2D escene usined 2D tileset?
    cheers
     
  40. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    DunGen works in 2D. It does work with Unity's tilemaps, but doorways will still need to place new gameobjects (probably sprites in 2D) for doors and walls - it can't manipulate the tilemap.
     
  41. Jeanseb05

    Jeanseb05

    Joined:
    Feb 29, 2020
    Posts:
    9
    Hi, I just bought Dungen and I was wondering if there is a way to use the depth scale API (get the depth scale number)
    So I can use it in my own code ?

    I've looked everywhere in the doc and cant seem to find it
    Thanks
     
  42. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Once you've got a reference to a tile component (it's attached to the root of your tile after it has been placed), you can use tile.Placement to access some information about where the tile was placed. tile.Placement.NormalizedPathDepth will give you a value between 0-1 describing how far along the main path it is.
     
    Jeanseb05 likes this.
  43. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    216
    Hello,

    Is there a way to generate the dungean without pressing play ?
     
  44. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Yes. From the top menu bar, go to "Window > DunGen > Generate Dungeon" to open a window that lets you generate a dungeon in the editor.
     
  45. Esprahit

    Esprahit

    Joined:
    Oct 8, 2012
    Posts:
    2
    Hello there!

    This asset looks pretty interesting for my project. Nonetheless, before I purchase it I got some questions.

    I want to do a 2D sidescroller game with tilemaps. Once the dungeon has been generated, can I manipulate the tiles / groups of tiles like walls (like delete them or move)? or even delete one room made of tiles from the dungeon?

    The real question is if there is some kind of integrity or rules that must be maintained once the dungeon has been generated or I can do whatever I want with it.

    The other question is if I can generate a new chunk of rooms in runtime and attach them to the previous one, with no new scene loading.
     
  46. NotQuiteSmith

    NotQuiteSmith

    Joined:
    Oct 27, 2013
    Posts:
    91
    Hi - I'm using Dungen in a networked game, using the same seed on all clients to build the dungeon. Is there an ID that I can use to identify each room/tile across all clients? This is so that I can create networked objects and link/parent them to the same room on all clients.

    Thanks!
     
    Last edited: Jan 1, 2022
  47. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    You can do whatever you want to the resulting dungeon really. The only thing to maybe consider is if you remove tiles completely, it'll invalidate the placement data (basically how far along the main/branch paths a tile is), but DunGen only uses that information while generating the dungeon.

    There's no built-in way to generate a new set of rooms and attach them to the previous set. With some custom code, it would be possible to generate a new dungeon and then position it so that a door in the new dungeon's starting room is adjacent to a door in the previous dungeon's goal room, but there's no guarantee rooms in the two dungeons won't overlap each other.


    There isn't a unique ID for each room, but you can use each tile's placement data to generate one. Once you have a reference to a tile, you could do something like this:

    Code (CSharp):
    1.  
    2. public int GetUniqueTileID(Tile tile)
    3. {
    4.     int uniqueID = tile.Placement.PathDepth;
    5.  
    6.     if(!tile.Placement.IsOnMainPath)
    7.          uniqueID += (tile.Placement.BranchDepth + 1) * 1000;
    8.  
    9.     return uniqueID;
    10. }
    11.  
     
    NotQuiteSmith likes this.
  48. KabirSwain

    KabirSwain

    Joined:
    Mar 9, 2021
    Posts:
    4
    Hi! I have been using DunGen and it is amazing! I am currently using prefab rooms to build an interactive home for training Reinforcement Learning models for a projectI just had a questions that I hope you can answer.

    I currently have 4 tilesets and each tilesets has a respective category of rooms. For example the kitchen tileset will have a few rooms which are only kitchen prefabs, the bedroom tileset will only have bedroom prefabs, etc. How do I force DunGen to use just one room from the kitchen tileset and one room from the livingroom tileset? I tried injecting the tilesets but that lead to multiple rooms from the same tileset being placed or failure of generating a successful "dungeon". Is there any way I can get this to work?

    Thanks!
     
  49. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    584
    Injected tiles should only appear once assuming you have only one entry per TileSet under the 'Special Tile Injection' heading. You'd also need to ensure your kitchen and living room tilesets don't appear in an archetype so that tile injection is the only way they can be spawned.

    It's possible to achieve something similar using a custom connection rule like this, but I'd still recommend tile injection if possible because you can mark injected tiles as required. The connection rule method only limits the maximum number of tiles that can spawn, it's possible you'll get zero.
     
    KabirSwain likes this.
  50. KabirSwain

    KabirSwain

    Joined:
    Mar 9, 2021
    Posts:
    4
    Thanks a lot for the reply! I will try this out and see if it works!
     
unityunity