Search Unity

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:
    622
    The assets in the demo scene were just made from the primitive shapes in Unity but you absolutely can import 3D models from other sources and use those. I just needed a quick scene to demonstrate how DunGen works and wasn't too concerned with how it looked.
     
  2. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    220
    Works great! Now I have some complex dungeons.
     
    hopeful likes this.
  3. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Did you ever get this working for iOS? Would be so awesome to have randomly generated DunGen levels in mobile games.
     
  4. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
  5. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Not sure about the size and shape of all the prefabs included in that package, but DunGen should work with pretty much anything you throw at it as long as you build rooms out of it that follow Aegon's recommendations.

    At its current stage DunGen uses rooms you build out of whatever shapes you have - be it primitive cubes or full blown prefabs like those Manufactura 4K sells (infact I have used his Top-Down Sci-Fi asset with DunGen in the past).
     
  6. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    Matching up doorways could be difficult with caves, in that you'd always have a seam of some sort ...?
     
  7. Alphalpha

    Alphalpha

    Joined:
    Oct 9, 2013
    Posts:
    74
    Well, you could have your doorways have flared walls that extend past the 'door', so that when they connect they a more natural-looking, non-planar seam.

    ./_\
    /
    ...\...\/_\/ _ = 'door'
    ..+...= /\ /\
    \ _ /
    .\ /


    If the cave walls have the same/similar textures it would probably look pretty good.

    Alternatively, you could just commit to placing standard frames around the 'doors', such as wooden support beams.
     
  8. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Has anyone successfully generated dungeons on mobile during runtime? If so, could you share what the performance was like? Thanks!
     
  9. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    I am really frustrated. I am using the attached image as my room. the room is square and have 4 doorways. I am still getting this error.

    Failed to generate the dungeon 200 times. This could indicate a problem with the way the tiles are set up. Try to make sure most rooms have more than one doorway and that all doorways are easily accessible.

    Can anybody help.
     

    Attached Files:

    • Room.png
      Room.png
      File size:
      339.3 KB
      Views:
      1,475
  10. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    I could imagine that the colliders of the outer walls and pillars overlap when DunGen tries to build so it throws an error. For a quick test you could just disable those and see what happens.
     
    hopeful likes this.
  11. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    What c-Row said is the most likely cause. Doorways being inside the rooms' collision boundaries is by far the most common problem I see with generating dungeons.

    I've pushed a new version here which should alleviate this considerably. Using the new version, doorways don't have to be on the very edge of your room bounds any more. DunGen will calculate the bounds as usual, then collapse them to fit the doorways where necessary. This is a very new version so it hasn't had much testing done yet.
     
  12. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    Thanks. I will try the new version. Though I understood what the problem was.
     
  13. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Wondering if I could use this asset with a 'cave' tileset (I could make it myself, but am curious about the specs to make it work with Daedalus). IE could I make a set of cave straight, angle, crossroad, dead-end, etc. 'tiles' and have DunGen put them together randomly into a maze? I would also want to set the start and end locations so that I could enter and exit said caves. Thanks!
     
  14. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    I have not tried it yet, but the only problem should be doing something to eliminate seams where the random cave segments join.

    This would be a general problem for any random dungeon generator, in that they are configured to connect with hallways and doors which have straight seams.

    If someone has already encountered this situation and solved it - with any dungeon generator - it would be great if they would post a picture.
     
  15. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    One possible solution would be to add a prefab which obstructs the view of the seam whenever the doorway is in use, like a doorframe for example. To avoid overlapping you would only add a frame to one side of your doorways so the connected tile provides the other one.
     
  16. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Well, I bought it and it was cake to use for a cave system. The newest build posted above eliminates any problem I initially had setting up cave dungeons. Basically you want to build your models with pretty similar sized doorways (although you can have a small/med/large set or whatever) and a flange on each end of the cave segment, and slightly inset your doorways (slightly), if your textures are seamlessly tiling between models it winds up looking pretty good: Using the brand new build it cozy's everything up nice for a seamless tunnel. For the user who asked above, the K4 underworld asset is built this way, so it should work fine. I'm sure I'll run into trouble and be back, but for now I'm stoked.
     
    hopeful likes this.
  17. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    Good to know! I figured there was a way to finagle it. :)

    Can you post a pic that shows your technique?
     
  18. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Sure, I'm working on something right now that I can post up. One recommendation/hope would be to put an "add selected objects from scene as new props" button to the local props set script. I've got 100 props in an average segment and manual drag n' drop is a bit tiresome.
     
  19. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Here's a pic of a cave system. I just bought DunGen a couple hours ago, so the system at this point is just made of one linear segment and one 4-way crossing segment, but it's a proof of concept.
     

    Attached Files:

    Karearea likes this.
  20. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    An ominous cave! It looks like Ethan might be in trouble! ;)

    Any shots that show where the seam would be? I'm not sure I'm seeing it (or not seeing it, if it is well hidden) in that picture.
     
  21. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    There's a seam about a foot in front of Ethan, and a few more down the hallway, but they blend pretty well I think... I don't notice them when running around. It could become a problem on segments that don't have the same tiling texture, I'll have to see, but I think there are pretty easy workarounds. Before the 4.2.2 version I couldn't get rid of small gaps where the tiles linked up, but now they squish up fine.
     
    hopeful likes this.
  22. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Is there any way to limit the maximum number of times in a row a certain tile is used? I have a straightaway section of cave, and if it is generated a bunch of times in a row with all the sub-objects in the scene I get wildly varying FPS from seed to seed...

    Also, would there be any way to get DunGen to use SECTR STREAM? VIS integration is working great, but with a lot of scene objects VIS doesn't seem to be optimized, STREAM chunks are actually dynamically loaded and would be quite helpful for improving FPS... It would involve somehow grouping tiles into STREAM chunks at runtime. Using both VIS and STREAM would be a killer combo.
     
    Last edited: Oct 2, 2014
    hopeful likes this.
  23. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    There's currently no way to limit the maximum number of times in a row a specific tile is used although I think that's something I could easily support in DunGen.

    For SECTR STREAM though, I'm not so sure. I was under the impression that it steamed level data from a file and wasn't really something that I could integrate into DunGen. Streaming should really only improve memory usage anyway. Unless you have a lot of gameplay logic running in tiles that are hidden by VIS, I don't imagine you'd see much of a performance gain.
     
  24. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    I was kind of thinking about trying to organize the levels in dunGen into sections in the flow editor and having each of those nodes being created as a sector. This would really make large levels not only possible but efficient for procedural use. I've posted in the SECTR thread about it, I'll see if it's realistic. Thanks for the response.

    Oh, and if you could point me in the right direction for a "fill local props script with selected objects in the hierarchy" script I would much appreciate it. I'm doing a lot of dragging and dropping but have no experience with scripting the editor.
     
    Last edited: Oct 4, 2014
  25. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    I can do one better than that.

    I've uploaded a new build here with some of the new features you suggested. This is a very new build so it's not fully tested.

    2.5.0 (Beta)
    - Added an option to prevent duplicate rooms from being placed right next to each other. Un-checking "Allow Immediate Repeats" in the dungeon generator settings will enable this behaviour. This won't prevent duplicate rooms appearing at the points where the main and branch paths intersect, though.
    - Added an "Add Selected" button to the Local Prop Set inspector that allows for all currently selected GameObjects to be added to the list at once.
    - Fixed a bug causing the bounding box of some rooms to be incorrect once rotated by DunGen.
     
    Last edited: Oct 4, 2014
    hopeful likes this.
  26. negativecap

    negativecap

    Joined:
    Jan 27, 2013
    Posts:
    99
    Wowza, that's fantastic! I'm really having fun with this product. It's taking some doing to get the performance I want with really complex scenes being generated at runtime, but it's so cool. Thanks for making it and being so eager to tweak it, I'll check out the new build.
     
  27. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    There's a bug in the current version that causes the ChosenSeed variable (in the DungeonGenerator class) to report the wrong value if DunGen has to retry while generating the dungeon. So if anyone has been using this to re-generate a past dungeon, that's why it's giving incorrect results. This is fixed in the 2.5.0 beta.
     
  28. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    So I am enjoying this so far. It works well for what I am using it for. A few requests that I think would be easy to add in and beneficial to everyone... These may already be in and I just don't know how to do it also.

    1) It would be nice if you could enable a debug mode for the entire system, and when enabled the different sections of the maze get color coded. For bonus points give us the option to chose that color. This would be huge is being able to see the start and end points when building a maze like dungeon.

    2) Currently the Dungeon Workflow determines the length/size of the dungeon. It would be nice if we could set this on a per-segment basis in the Flow editor. I would like to add in a labyrinth archetype sections to the dungeon. To do this I created a single tile with 4 walls/doors and nothing else and as long as I leave the dungeon size under 50 it works just fine. However I don't have any direct control over how large this labyrinth is with respect to the rest of the dungeon.

    DunGenTest.PNG
     
    Last edited: Oct 5, 2014
  29. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    1. That should be easy enough to do. I thought I already had some debug rendering in place but it looks like I removed it at some point.

    2. This is trickier. I'd have to re-work how I'm doing some things in the generation process. It should be doable but I don't know when I'll be able to make a change like this. This is a feature I had planned for the new flow-graph editor in v3.0 but that's been put on hold.
     
  30. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    Thanks for the info - It's your project so please do it the way you want. I can work around it for now - if you do end up putting it in though I would be super happy!
     
  31. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    Any tricks on getting the Poor Man's Nested Prefab (referenced in the description post) working with this? I created a small room. Each of the GameObjects containing the wall script is it's own unique piece, and then as a child I add an empty game object and put the nested prefab inside. It shows up fine on the screen when I manually place it - but when I attempt to generate a dungeon with it it doesn't show up. No errors are thrown.

    I will keep working towards a resolution and post back if I figure it out. But if you have any pointers I would appreciate it.

    ---
    update: So I have been trying to get the nested prefabs to work. I am not sure where the issue is at, but if I create the dungeon in the editor (Window->DunGen->GnerateDungeon) it works fine, when I attempt to generate it at run time nothing happens. I've added in a bunch of Debug.Logs and can see it doing all the work to generate the dungeon, but nothing ever gets added. Any ideas on where the problem might be?

    More info: I copied over the code that the Editor uses when generating the dungeon into the run-time which then adds a new game object that contains all the pieces. All the pieces are there with the nested prefabs, the prefabs just don't get rendered for some reason when generating the dungeon at run-time.

    SOLVED: So it turns out that the Poor Man's Nested Prefab only generates the object when it is placed in the editor. To solve this I just added this to the bottom of the class and it works perfectly. Hope this helps others out.

    public bool generateAtRuntime = true;
    void Awake()
    {
    if (generateAtRuntime)
    OnPostprocessScene();
    }

    Edited the code above to reflect the need for this to be called at awake and not at start.
     
    Last edited: Oct 8, 2014
  32. AlexSledge

    AlexSledge

    Joined:
    Nov 13, 2013
    Posts:
    17
    Minor request - mind adding the version applicable to the first page of the PDF doc (assuming you are updating it as you update the asset)?
     
    Noctys likes this.
  33. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    I always appreciate it when there's a version number in the readme. I don't always have the most recent version in my project.
     
  34. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    I was just about to post and say that I should have noticed the part where he's using a PostProcessScene attribute to call the function that places the objects in the scene; Which means it's only run when the scene is built. Glad you found a solution. I should have actually tried the "Poor man's nested prefabs" solution before mentioning it. I'll have to figure out how to mention that in the Asset Store description or just remove the recommendation all together.

    Yeah, I can start doing that.
     
  35. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    There are other issues with the Poor Man's Nested Prefab. I am going to see how much I can fix and if I can fix enough I will probably write up a blog article on an improved version. If I do I will post a link here.
     
    c-Row and hopeful like this.
  36. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    ... Edit: Disregard the below - After rereading the instructions I think I have all my doorways on backwards (blue-line pointing in)... I am going to fix all my doors and will let you know the outcome.... After further research it was found this was do to my method of doing nested prefabs.

    ------------------------------------------------

    I seem to be getting a lot of overlap, and when I look at the dungeon layout in Scene view I see what I assume are bounding boxes with red outlines. Most of the boxes are 2D (x & z) - and several of them to not line up to what I have selected. Any ideas on what I am doing wrong?
     
    Last edited: Oct 10, 2014
  37. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    There was a bug introduced in 2.4.2 which causes bounding boxes to sometimes be 1D lines. I fixed that in beta 2.5.0 (here) but I've never seen bounding boxes appear as squares. What version are you using?

    I've never seen this problem before, I'll see if I can reproduce it somehow. One thing I did notice is that your doorways seem to be facing the wrong way in that first screenshot. The blue line should be facing outwards. I don't think that would be causing the problems you're seeing though.
     
  38. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    I believe I am using the latest version (downloaded and installed from the link above) when I first started using this (about a week ago) -- not sure if it overrode the version I installed from the app-store though. Is there a way to tell what version I am using?
     
  39. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    There's no way to see the version number I don't think. But if you have a "Allow Immediate Repeats" checkbox in the dungeon generator options, you're using the newest beta version.
     
  40. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    Yes I have that option, thanks! Still trying to rebuild all my rooms with the line pointed out. Will update you when I have that done and see if there are any changes. thanks again!
     
  41. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    So I fixed the doors on my first 3 segments; I am not yet getting any overlap so I think that was related to the doorways being placed backwards. I am still however getting what I assume is the wrong type of highlighting when I have segments or the entire dungeon highlighted. This could be related to the way my Nested Prefabs are generated too. Anyway, if you want to look into it further and need more data from me I will be happy to provide it.

    EDIT: This was definitely related to the Poor Man's prefab. I changed that part I added in to create the objects at run time from Start to Awake and it works perfectly now.

    DunGen - Line offset.PNG DunGen - 2D Grid.PNG
     
    Last edited: Oct 8, 2014
  42. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    Sorry - it's me again. I am slowly working through all this. I double checked everything on this one and can't find a reason for what is happening. In the image below you see a stairway that is connected to 2 other boxes. The boxes at the top and bottom are both part of a single stairway prefab. However the box at the top does not seem to get included in the vertical bounds (however it does get included in the horizontal bounds. Any ideas?

    DunGen - 2D Grid.PNG
     
    Last edited: Oct 8, 2014
  43. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    Found a fix - looks like the CondenseBounds method doesn't account for rooms with multiple floor heights. I was able to fix this by changing the first loop in the method to read as follows:

    foreach (var doorway in doorways)
    {
    min = Vector3.Min(min, doorway.transform.position);
    max = Vector3.Max(max, doorway.transform.position + new Vector3(0, doorway.Size.y, 0));
    }


    This corrected the issue for me, although I am not sure if it will have other side effects later on down the road....

    Edit: Just wanted to drop in an image of what this AMAZING generator can do. I only have 5 room types (single cell, a 3x1 hallway, 3x3 square, a 3x3 cross and stairs)... Those all get combined into this. Thanks!!!

    DunGen - large maze - 0001.PNG
     
    Last edited: Oct 9, 2014
    c-Row, vvander and hopeful like this.
  44. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    So I ran into more snags with the poor-man's nested prefabs when trying to use it with an actual build. I worked through that and have code that works with very minimal issues (all with the editor, none at run-time). I wrote up a quick blog entry on it here: http://beyondmindless.com/bmd/2014/10/09/unity-nest-prefabs-and-building-scenes-at-runtime/

    I need to go back and add in some details on the known issues. But for now this is better than nothing. I hope to have it fully updated within the next day or so.
     
    Last edited: Oct 9, 2014
    AlexSledge likes this.
  45. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    Sorry, I was unable to respond yesterday. I'm glad you've managed to get things working. And thanks for taking the time to post your experiences and fixes to any problems you've encountered. Hopefully Unity will give us full support for nested prefabs natively soon.

    Looking at your fix for the problem in CondenseBounds, I don't think it will cause any negative side-effects, I think it should have been like that from the start. I've included this fix in 2.5.0 beta (modified so that it also works for dungeons not using +Y as up).
     
    Noctys likes this.
  46. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Hi it's possible to generate by seed on start
     
  47. Morgenstahl

    Morgenstahl

    Joined:
    Oct 12, 2014
    Posts:
    1
    Hello, I seem to be having trouble dealing with Local Prop Sets. The current problem is I can make a prefab prop, attach the local prop set script (specifying the props) and then place the prefab in the tile prefab. At this point, the prop is not swapped out with a prop from the set. I believe there may be a step omitted in the documentation, as it does work if I add the set props as child items under the prefab prop.

    [That said, the resultant prefab is tedious to update as Unity does not currently support nested prefabs. The prefab connection is invariably broken in this process. Is there a known workaround? Thanks for your help guys!] *Awkward, didn't realize there was a post right above that was talking about nested prefabs. Is Dungen going to natively support nested prefabs in the near future? Alternatively could try finding own solutions.
     
    Last edited: Oct 12, 2014
  48. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    Yes, you can specify a seed when generating a dungeon.

    I'm not sure I understand the first part. It sounds like you're referencing objects from the scene in a prefab, which I'm pretty sure you can't do unless those objects are also part of the same prefab (otherwise Unity wouldn't know about them). I'm probably misreading that.

    About the nested prefabs, I'm not sure what can be done about it other than wait for Unity to implement full support themselves. There's a couple of 3rd party solutions, some are free, some are paid - but none of them are a perfect fix, only Unity can do that. I'll look into it some more but I can't guarantee a built-in solution in DunGen.
     
  49. vvander

    vvander

    Joined:
    Jan 18, 2011
    Posts:
    72
    If anyone is wondering why their tiles aren't lining up correctly, make sure you set their transform locations to 0,0,0! Took us ages to figure out the issue. Aegon Games, thank you for this incredible asset! Perhaps you could look into automatically setting tile prefab positions to 0,0,0 before doing the generation in v2.5.0? I can't imagine this is intended behavior.

    In a few weeks we'll be ready to announce our next game which features DunGen generating an open world (without any modifications to DunGen so far by us). I'll be back here to post screenshots when we're ready to be more public.
     
    hopeful likes this.
  50. Aegon-Games

    Aegon-Games

    Joined:
    Mar 7, 2014
    Posts:
    622
    I've just released a new build of 2.5.0 (beta), here's the new change log (newest additions in bold):

    2.5.0
    - [ADDED] an option to reduce the frequency that duplicate rooms are being placed right next to each other. Un-checking "Allow Immediate Repeats" in the dungeon generator settings will enable this behaviour.
    - [ADDED] a button to the Local Prop Set inspector that allows for all currently selected GameObjects to be added to the list at once.
    - [ADDED] debug rendering which can be enabled for runtime dungeons by checking the "Debug Render" box in the dungeon generator settings. Tiles will be colour coded red > green for the main path and blue > purple for branch paths.
    - [ADDED] an option to Dungeon Archetypes to use specific tile sets as caps to branch paths and specify if they should be used "instead of" or "as well as" the standard tile sets. NOTE: Using "instead of" still doesn't guarantee that all branch paths will be capped with a tile from these sets.

    - [FIXED] a bug causing the bounding box of some rooms to be incorrect once rotated by DunGen.
    - [FIXED] a bug causing the ChosenSeed variable to be set incorrectly after a failed generation attempt.
    - [FIXED] Tile prefabs with non-identity transforms will no longer appear offset in the dungeon.

    Thanks, I've fixed that in the latest build. I'm sure I fixed it before but it seems to have cropped up again. Looking forward to seeing more projects using DunGen :)
     
    Noctys likes this.