Search Unity

Map Graph – Node-based Random Map Generation

Discussion in 'Assets and Asset Store' started by InScatterbrain, Aug 3, 2020.

  1. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    This looks like a bit of rounding issue.

    The graph uses the Connect Area Graph (Closest Border Points) node inside one of the sub graphs.

    It tries to connect areas by matching up the border points that are closest to each other. In this case there are two valid options, because they're square. It picks the upper option.

    Then the Draw Connections node draws the connection. If it's two pixels thick, it draws one line between the two connected points and one above that. Creating the result you're seeing.

    If you're using an odd number for width and height, it will always prefer the more centered point, because the Connect Area Graph (Closest Border Points) node prefers points closest to the area centers, which is why this issue doesn't occur in that situation.

    To solve this, I'm thinking that if there are two equally valid options for connecting two areas, it should pick the bottom one instead of the top one, due to the way drawing works that would make more sense.

    Sorry if this is a bit of complicated rant. :D The tldr is that I think I should make a bit of an adjustment to how the node decides which points to connect, so that the connections line up better in a case like this. I'll start working on this soon and I'll get back to you when I've implemented a solution. :)
     
    Tom-Kazansky likes this.
  2. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    It uses Unity's own GraphView system. :)
     
    andyz likes this.
  3. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    I'm working on the modification that should resolve the issue you're having. It will be included in the coming patch, but that will take a little while before it's released. If you need a solution right now, let me know, and I'm sure we can figure out a workaround for the time being. :)
     
  4. Creiz

    Creiz

    Joined:
    Jun 6, 2017
    Posts:
    130
    Hi!

    I want to use the RPG template. Is there a way that I can select one or two random squares out of the BSP and replace them with premade rooms?
     
  5. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    What you can do is, use the squares to create a mask and pass that mask to a Randomly Stamp Tilemaps node. Then assign the number of premade rooms you want to the Max. placements port. Something like this:

    upload_2022-9-28_13-42-3.png

    Does this answer your question?
     
  6. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    Can we get a bool to have "shift texture" not spill over?
    I also can't get texture input parameters to work, I tried several things and a texture2D input just comes up blank

    ultimately what I want to do is mask off regions of the map, such as black out the bottom half of the map with a mask, but I've hit a roadblock at every corner trying to do so so far!

    I even tried to do this and the shift didn't work

    upload_2022-9-28_9-12-45.png
     
  7. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Yes, that sounds useful. I'll put it on the todo list. Thank you for the suggestion!

    I'm sorry that this is giving you issues. It sounds like there might be a bug there. I'll look into it and will get back on that.

    Shifting a texture doesn't really work here, because of the spill over you mentioned earlier. Though I think there is an easier way to get the result you want. Would something like this work for you?

    upload_2022-9-28_15-29-14.png

    If you want to make something similar to mask the upper part of the map instead, for example, you can set the Offset port to 0x50.
     
  8. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    What might be the problem for the Texture2D input parameter, is that the "Read/Write Enabled" option should be enabled for the texture.
    upload_2022-9-28_22-37-22.png

    Normally, if that option is not enabled, an error should show up in the log, but currently it might not (due to a bug that'll be fixed in the upcoming version).
     
  9. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    both of the suggestions work! enabling read write and the stamp suggestion! thank you!

    I am getting something weird though. the preview in the "texture to mask" works, but when I apply the mask it get's all messed up
     
  10. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    forgot to post the screenshot upload_2022-9-28_20-38-11.png
     
  11. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    I fixed the above issue by scaling the image to target size upload_2022-9-28_21-3-30.png
     
    InScatterbrain likes this.
  12. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Great! I'm glad you were able to resolve that. :)

    Applying a mask will indeed not work correctly on a texture of a different size. I'll add something about that to the documentation.
     
  13. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    does this asset have a discord for people using it?

    I am currently trying to find the best way to have say, 2-3 rivers start at the top, naturally snake around and end at 2-3 exits near the bottom
     
  14. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Not at the moment, but I'm considering to set one up. :)

    There's probably a couple of ways to do it, but one way is to get a point drawn at the top and bottom of the map (using a similar masking strategy as before) and connect those points together using a random walk node.

    You might need to fiddle a bit with the settings to get the result that you want, but I think that would be a good place to start.

    If you'd like an example, just let me know. :)
     
  15. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    I would love to see your idea, I am currently doing exactly that. I draw 3 points up top then 3 points down bottom. one question, how would we merge 2 textures? I have my way of doing the river drawn out (not great, but it works), I want to now combine this with other textures in my graph but I can't really find a way to do this
     
  16. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    This is what I had in mind:
    upload_2022-9-29_12-4-42.png

    Make two different masks, one masks of everything but the top row and the other everything but the bottom row, then use each to draw a single point, followed by drawing a connection between those using a random walk. But there are likely other ways to do it, if this is not really the effect you're looking for.

    The easiest way to combine textures is to stamp one on top of the other. For example, if I want to add the river to a map of grassland, you could something like this:
    upload_2022-9-29_12-10-7.png

    Though that might not be what you want. It depends on what textures you have and how you want to combine them.
     
  17. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    ah, ok! this is similar to what I am doing atm. stamp is the thing I was missing when digging around. Is there any way to use 2 different color points to set A as the start and B as the target? that way if I use 2 points above and 3 points on the bottom, the 2 up top will all seek towards the other colored points below?
     
  18. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Hmm, not exactly. By default the Extract Areas & Draw Connections nodes draw the least amount of connections as possible to connect everything together, using a minimum spanning tree. You can work around this and use the fully connected graph, by using a series of nodes like this instead:
    upload_2022-9-29_12-58-45.png

    This way there are more connections between the top and bottom points, so this might be closer to the result you're looking for, but there's no easy way I can think of to not connect the start end points to each other, sorry. :(

    I'll look into if it's possible to add that feature in a future release though.

    EDIT: I suppose you could cut off the top and bottom parts to get rid of those connections though.
     
    Last edited: Sep 29, 2022
  19. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    I combined a few ideas here to come up with what I am happy with! I did 1 point in the top, middle and center, connected those using the random walker, then I added 3 new random points in the center and connected those to the original area using random walker again. results!

    upload_2022-9-29_7-41-41.png
     
    InScatterbrain likes this.
  20. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Nice, looks good! :)
     
  21. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    does this have some kind of way to place prefabs using autotiling? like using rule tiles with prefabs? I just learned that using prefabs in tilemaps using rule tiles is really weird. the prefab isn't in the hierarchy at all, it loses its parent for some reason? I dunno, just seems like we could really use a way to place prefabs themselves using something like a rule tile. does it exist?

    similar to this pretty much. benefit is you get the actual object in the hierarchy and you get the actual prefab being placed
     
    Last edited: Sep 30, 2022
  22. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    As far as I know, there isn't something like rule tiles for prefabs in Unity itself. There might be a third party solution available, such as in the video, but if there is, I'm not aware of it. (If there is I'd love to hear about it!)

    I agree that using the tilemap system for this has some downsides, not having the game objects in the hierarchy at edit time makes it hard to make certain modifications.

    It is something I'd love to provide an alternative for, but it seems to me that that would be whole other project in it's own right.

    But I'll put this higher onto the priority list. Perhaps I can make some tools that takes care of some of the downsides of working with Unity tilemaps and prefabs instead.
     
  23. MimiKitty

    MimiKitty

    Joined:
    Dec 13, 2018
    Posts:
    20
    in the video above he made his own rule tile script that his world generator uses to place the prefabs, similar to the layer 3D example scene.

    could be something like "texture to gameobjects using map graph rule tile"

    the map graph rule tile could be similar to the above video where you can assigning which prefab is placed based on that "named colors" position compared to other pixels within the named color
     
  24. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Yeah, something like that would be awesome. I'd have take a look at what the options are for implementing something like this in Map Graph. It'd likely take a while to implement though. So I can't really make any promises about if or when it'll get implemented. But I will look into it. :)
     
  25. unity_0DF4EB144C45323B4366

    unity_0DF4EB144C45323B4366

    Joined:
    Aug 2, 2022
    Posts:
    6
    upload_2022-10-1_2-31-19.png


    upload_2022-10-1_2-32-16.png


    hi, I'm following along with your tutorial getting started. my map graph doesn't have any place to put the tilemap in.


    upload_2022-10-1_2-32-54.png
     
  26. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Do you maybe have multiple graph files? Are you sure you assigned the right one to that runner component? The runner should display input fields for the input parameters of the assigned graph.
     
  27. unity_0DF4EB144C45323B4366

    unity_0DF4EB144C45323B4366

    Joined:
    Aug 2, 2022
    Posts:
    6

    upload_2022-10-1_19-52-48.png


    not really. all i see is that processed list that's empty.
     
  28. unity_0DF4EB144C45323B4366

    unity_0DF4EB144C45323B4366

    Joined:
    Aug 2, 2022
    Posts:
    6
    Sorry my bad. i did it from the start again i missed a step :) now it works fine. its great.
     
    InScatterbrain likes this.
  29. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    No worries! Glad you got it resolved. Let me know if you run into anything else. :)
     
  30. unity_0DF4EB144C45323B4366

    unity_0DF4EB144C45323B4366

    Joined:
    Aug 2, 2022
    Posts:
    6
    Well when you offer.

    upload_2022-10-2_20-13-54.png

    how would one create borders inside a area? for example here I'm trying to generate a forest inside the land. how can i make it not touch lets say 2-4 blocks from the edges off mask? or better yet how to make the mask a bit thicker then the extracted area ?
     
  31. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Here's one way to do it:
    upload_2022-10-3_9-36-3.png

    Before you extract areas draw an outline on the land part using the Draw Outline node. Make sure you set the "Overlap?" port to true, otherwise it will draw an outline outside the land part instead of on the inside.

    Then you can extract the area like you did before and get the mask from it. :)

    Would this solve your issue?
     
  32. wats_Games

    wats_Games

    Joined:
    Aug 24, 2022
    Posts:
    2
    Hi, I recently bought the Humbled Bundle bundle Map Graph came with and was wondering if there is any way to add collision to the graph this is what I have so far:
    (I was following the room like tutorial) upload_2022-10-7_22-25-28.png upload_2022-10-7_22-25-42.png
    Thanks in advance.
     
    Last edited: Oct 8, 2022
  33. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    You can handle collisions outside of Map Graph using Unity's own components.

    For 3D gameobjects, you can use the default collider components. If you're unsure on how to use those, here's a short tutorial that should help you get started: https://styly.cc/tips/colider-introduction/

    For tilemaps you can use a tilemap collider. There's a short tutorial about it here: https://jon-jenkins.medium.com/adding-colliders-to-tilemaps-in-unity-96e996908145
     
  34. wats_Games

    wats_Games

    Joined:
    Aug 24, 2022
    Posts:
    2
    Thanks for the help.
     
  35. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    No problem. Let me know if there's anything else you need help with. :)
     
  36. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    I've had some questions about whether there's a Discord server for Map Graph, so I've set one up. :)

    It's meant to become a place where Map Graph users can come and discuss Map Graph and game development in general. I'll be around from time to time to answer questions, but if you need official support, please post your questions here on the Unity forums or sent an email to support@insanescatterbrain.com.

    You can join the Map Graph Discord server here.
     
    Last edited: Oct 11, 2022
  37. NandusMasta

    NandusMasta

    Joined:
    Apr 9, 2011
    Posts:
    63
    Hey. This is perhaps a stupid question to ask, however I am sorely in need of assistance here. I am trying to avoid the edges of a texture while drawing landmasses. To this point I have a draw circles node with a center points array of Vector2Int, the idea is to start from center points, add noise and that way avoid the edges. However I can't assign those in the editor. Do I need to do it via script? Also I tried to use the random points node, thinking I could use it's bounds to specify points only near the center, however I could never get to do it; as the bounds values would only define how many points are generated and if they are mostly vertical or horizontal. Is that how the node is supposed to behave or am I using it wrong(probably). Thanks in advance for whatever assistance you may provide on this!

    Update: I got this to work using masks, however I still would like to know if I could do it as I initially wanted to. Also is there a way to quickly add random noise to the border of a texture?
     
    Last edited: Oct 16, 2022
  38. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Yes, it's not (yet) possible to assign input parameters of array types in the inspector. I suppose it would be useful to be able to assign arrays of certain types, at least, in the inspector. I think I'll put that on the todo list actually. For now using a script would be the way to go.

    The bounds merely specify how big the area is, in which you want to generate points. If you want to make sure they're only drawn in the center, one way you could do it, is by generating points within smaller bounds and then stamping them onto a texture with larger bounds. Something like this:
    upload_2022-10-17_11-55-15.png

    Sorry, I'm not really sure what you mean by generating points mostly vertical or horizontal, could you add like a screenshot or something that would help me understand what you mean?

    Using a mask is the way I would recommend doing this. Is there a specific reason you'd prefer doing this another way?

    You could achieve this effect by first drawing a border and then using that as a mask for drawing random noise on that border.
    upload_2022-10-17_12-0-19.png

    I hope I understood your questions correctly and that this is helpful in any way. If it's not, please let me know and I'll try to help you further the best I can. :)
     
  39. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.19.2 is now available.

    Changes:

    • Fixed broken WebGL builds, caused by the DLL conflict fix. The new solution should now resolve possible DLL conflicts without breaking WebGL builds.

    • Floats assigned to Vector2Ints are now rounded down in certain cases, to avoid situations where they might be rounded up to a point that doesn't exist within a texture or bounds.

    • Made some improvements to drawing lines, so that the result is more consistent.

    • Improved the way exceptions are handled so that debugger features like failed node highlighting works more reliably.

    • Map Graph's installed and latest versions are now displayed in Map Graph's about window.

    • Attempting to set a color outside of the texture's bounds now throws an exception with a more concrete error message.

    Check out the complete changelog here.
     
  40. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    58
    Hi,
    The issue with horizontal manhattan connection, that I reported a while ago, has been fixed in the new version.
    Thank you for your hard work! :D

     
    InScatterbrain likes this.
  41. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Great! I'm glad to hear it. :)
     
  42. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.19.3 is now available.

    Changes:

    • Added the "Map Graph/Tile" option to the create menu to replace the "Tile" option that was removed by Unity.

      This allows creating single Tile assets again, without the need for creating a tile palette.
    • Fixed bug where Map Graph wouldn't run in multi-threaded mode in the editor with the project's build platform set to WebGL.
      Multi-threading will still be disabled when in play mode, to simulate this limitation of WebGL builds.
    • Manual: Updated the Getting Started tutorials.

    • Manual: Updated troubleshooting page.

    • Manual: Added information about using Unity's Rule Tile system to generate game objects, instead of tiles.

    • Manual: Added a section about creating multiple layers using game objects to the "Using prefabs instead of tilemaps" page.

    • Made various minor refactoring changes.

    Check out the complete changelog here.
     
  43. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.19.4 is now available.

    Changes:

    • Added a link to the Map Graph Discord server to the about window.

    • The "New Version" window should no longer open in a too small size.

    • Ports of SaveData now have their own color and are square like for other object types.

    • Added tooltips for the options on the Map Graph Runner component.

    • Updated DeBroglie to version 2.0.0, which should result in better performance when using WFC.

    • Updated Delaunator to version 1.0.10.

    • Updated QuikGraph to version 2.5.

    • Unity no longer needs to fix the namespaces when importing Map Graph in a project using Unity 2022.1 or newer.

    • Manual: Updated node index.

    • Manual: Updated troubleshooting page.

    Check out the complete changelog here.
     
  44. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    I seem to be struggling with an important fundamental aspect of using this.
    I want to use this to generate maps of 3D Prefabs. Each prefab is a fixed size. Let's say 50x50 units as an example.
    I can generate a graph that makes a texture and then converts that texture to prefabs as per the tutorial and sample scene, but the problem I have is that every pixel in the texture is treated as 1 unit in the scene. So my 50x50 sized prefabs are all stacked up every single 1unit in the scene which is clearly not what I'm going for.

    How do I control this -- for lack of a better word -- grid size so that a pixel in the source texture is say a 50x50 rectangle in the scene that will be populated by a prefab?

    IOW I want to work with prefabs other than 1x1x1 cubes.
     
  45. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Ahh my bad. After digging through the code for the TextureToGameobject node I realized this is simply a width and height property in the Prefab Set that I totally overlooked!
     
    InScatterbrain likes this.
  46. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    No worries. Glad you solved it.

    Let me know if there's anything else you need help with. :)
     
  47. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.20 is now available.

    Changes:

    • Input parameters of array types are now assignable in the inspector, if the element type was already assignable in its singular form.

    • Map Graph's serializer now uses invariant culture to serialize objects, to fix an issue where certain types, such as floats, wouldn't get stored correctly depending on the system's culture settings.

    • Added "All" out port to the Areas Special Border Points node that contains all the special border points in a single set.

    • Random BSP Rooms node now checks if a room is at least 1x1 in size.

    • Removed the Mask and Placements output parameters from the Cellular Automata Texture subgraph, as they returned the results of the internal Randomly Fill Texture node, which is confusing.

    • The "New Update" window now has a button to open the package manager and the Open Asset Store button has been reduced in size.

    Check out the complete changelog here.
     
  48. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
  49. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.20.1 is now available.

    Changes:

    • Input parameters of type Pair<Vector2Int> can now be assigned from the inspector.

    • Input parameter array foldouts now open/close when clicking the label as well as the arrow icon.

    • Input parameters array fields are now accompanied by a element count field, for easy resizing.

    • Fixed bug where deleting an item from a input parameter of array would trigger a warning and corrupt the array.

    Check out the complete changelog here.
     
  50. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Map Graph v1.21.1 is now available.

    This release includes changes for v1.21.

    Map Graph now requires the Editor Coroutines package. This is usually installed by default in new Unity versions. If it's
    not Map Graph will install it for you.

    v1.21.1 changes:

    • Fixed issue where changes to input parameters wouldn't persist if the Map Graph Runner component was part of a prefab.

    v1.21 changes:
    • When running a graph asynchronously, the execution of code that needs to run on the main thread will now be spread over multiple frames by default,
      to further reduce freezing and stuttering.

      The time spend on each frame can be changed on the Graph Runner component, by adjusting the "Target Time Per Frame" setting.

      If you wish to restore the previous behaviour, you can uncheck the "Enable Main Thread Time Per Frame Limit" setting on the Graph Runner component.

    • There's now a OnProgress event on the Graph Runner component, which you can hook into to track the progress of the graph processing.

    • Fixed issue that kept the "Prevent Clear?" option on the Texture To Tilemap node from working correctly.

    • Manual: Updated the create your own node section to the manual.

    • Manual: Updated the section on running a graph asynchronously to the manual.

    • Manual: Added a section on how to use the new OnProgress event.


    Check out the complete changelog here.