Search Unity

Map Graph – Node-based Random Map Generation

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

  1. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    Hello! Happy New Year!
    I spent the holidays playing around with Map Graph and I'm really enjoying, especially now that I feel I have a handle of it.
    However, it's unclear to me how to output a texture from Map Graph to be used by other Unity tools. I'd like to generate a terrain with Map Graph, taking that data to use in a tool like Polaris (https://assetstore.unity.com/packages/tools/terrain/polaris-2021-low-poly-mesh-terrain-editor-196648), which can generate a 3D mesh using Textures, or Unity Terrain Data, or RAW.

    I found this page in the manual: https://mapgraph.insanescatterbrain.com/manual/output_parameters.html... but I'm not sure what it does (or how it works).

    Ideally, when Map Graph Runner runs, it would write a 2D texture to a file, and then I could use the Processed() event to generate terrains with Polaris using that 2D texture file. Does that make sense?
     
  2. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    I think you're on the right track.

    First off, you'd need a Texture2D output parameter:
    upload_2023-1-8_13-57-0.png

    Then you'd need to assign to it in your graph. Map Graph works with its own TextureData object, so you'll need to convert that to a Texture2D before passing it to the output parameter. There's a node for that:
    upload_2023-1-8_13-57-51.png

    After that you can plug in to the OnProcessed event like in the page you linked to.

    The OnProcessed event gets invoked every time the graph runner has finished processing. You should be able to get the texture from the output parameters like this:
    Code (CSharp):
    1. var texture = outputParameters["Texture Output"] as Texture2D;
    After that you should be able to do whatever you want with the texture. :)

    Does this answer question?
     
    daville, Railon23 and HeyBishop like this.
  3. InScatterbrain

    InScatterbrain

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

    Changes:

    • Added weights to prefab, tile and tilemap set types. Changing the weight of an entry will change the probability of it being used when generating a map.

    • Min. and max. zoom level can now be set in the new settings window. Which you can find under Tools > Map Graph > Open Editor Settings.

    • Added the Subtract Mask node, for subtracting one mask from another.

    • Made modifications to the initialization scripts to avoid situations where the importing of Map Graph assets gets unnecessarily triggered in newer versions of Unity.

    • Manual: Added "Changing tile/prefab/tilemap set probabilities (weighted random)" page.

    • Manual: Fixed dead link on the Tilemap Sets page.

    • Manual: Added section about coordinate system to the "Creating your own nodes" page.

    Check out the complete changelog here.
     
  4. dhodvogner

    dhodvogner

    Joined:
    Feb 5, 2014
    Posts:
    3
    Hi,
    I try to use Map Graph for one of my projects, but when I try to create a Prefab Set the UI seems broken and I can't add prefabs to the types. (Unity 2021.3.16f1)
    Any idea why this is happening?
    Screenshot 2023-01-23 162208.png
     
  5. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Yes, this is a bug in v1.22. Map Graph v1.22.1 has been submitted, but has yet to be approved. It should resolve this issue.

    In the meantime you can fix this manually, by importing the unitypackage file that's attached to this post.

    Sorry for this inconvenience.
     

    Attached Files:

    dhodvogner likes this.
  6. dhodvogner

    dhodvogner

    Joined:
    Feb 5, 2014
    Posts:
    3
    Thanks for the quick reply :) It's working now!
     
    InScatterbrain likes this.
  7. InScatterbrain

    InScatterbrain

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

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    I've been getting reports about a bug that started showing up with Unity 2021.3.16. This seems to be related to the latest version of the Burst package. So right now, I'm guessing this is something that needs to be fixed on Unity's end, but I'll keep investigating for a solution on Map Graph's end.

    If you're running into the following error message, my advice would be to stick with Unity version 2021.3.15 or lower, for now.
    Code (CSharp):
    1. Failed to find entry-points:
    2. System.Exception: Unexpected exception while collecting types in assembly `InsaneScatterbrain.MapGraph.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null` ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'QuikGraph_MapGraph, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null'
    3.   at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00105] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    4.   at zzzUnity.Burst.CodeGen.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00039] in <a2dd15248a25411e914af2a2c82fb63f>:0
    5.   at Burst.Compiler.IL.AssemblyLoader.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00079] in <a2dd15248a25411e914af2a2c82fb63f>:0
    6.   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00038] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    7.   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    8.   at Mono.Cecil.TypeReference.Resolve () [0x00006] in <ebb9e4250ed24cbfa42055e3532ef311>:0
    9.   at Burst.Compiler.IL.Server.EntryPointMethodFinder.CollectGenericTypeInstances (Mono.Cecil.TypeReference type, System.Collections.Generic.List`1[T] types, System.Collections.Generic.HashSet`1[T] visited) [0x0002f] in <a2dd15248a25411e914af2a2c82fb63f>:0
    10.   at Burst.Compiler.IL.Server.EntryPointMethodFinder.CollectGenericTypeInstances (Mono.Cecil.AssemblyDefinition assembly, System.Collections.Generic.List`1[T] types, System.Collections.Generic.HashSet`1[T] visited) [0x00057] in <a2dd15248a25411e914af2a2c82fb63f>:0
    11.   at Burst.Compiler.IL.Server.EntryPointMethodFinder.FindEntryPoints (System.String[] rootAssemblyNames, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Server.ProfileDelegate profileCallback, System.Boolean includeRootAssemblyReferences, System.Boolean splitTargets, Burst.Compiler.IL.Helpers.DebugLogWriter debugWriter) [0x0019d] in <a2dd15248a25411e914af2a2c82fb63f>:0
    12.    --- End of inner exception stack trace ---
    13.   at Burst.Compiler.IL.Server.EntryPointMethodFinder.FindEntryPoints (System.String[] rootAssemblyNames, Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Server.ProfileDelegate profileCallback, System.Boolean includeRootAssemblyReferences, System.Boolean splitTargets, Burst.Compiler.IL.Helpers.DebugLogWriter debugWriter) [0x001d9] in <a2dd15248a25411e914af2a2c82fb63f>:0
    14.   at Burst.Compiler.IL.Server.FindMethodsJob.Execute (Burst.Compiler.IL.Server.CompilerServerJobExecutionContext context) [0x00133] in <a2dd15248a25411e914af2a2c82fb63f>:0
    15.  
    16. While compiling job:
    17.  
     
    Last edited: Jan 26, 2023
  9. HeyBishop

    HeyBishop

    Joined:
    Jun 22, 2017
    Posts:
    238
    Pardon the late response! This has been very helpful! Thank you!
     
    InScatterbrain likes this.
  10. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    No worries, glad it was helpful! :)
     
  11. InScatterbrain

    InScatterbrain

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

    Changes:

    • Fixed bug that would draw lines on the Random BSP Rooms node's preview image and log an error, in situations where the rooms would be 1 in size in either dimension.

    • Fixed bug where the Replace Color node would throw an exception when find and replace colors were the same, whereas it should output the input texture and log a warning.

    • Fixed the "Connected Caves (Cellular Automata)" subgraph so that it now works correctly with non-transparent texture input.
    I forgot to post the changes for v1.22.2 so here's that change:
    • Fixed a bug that caused the weights on set entries to not get saved correctly, resulting in only the first entry being used.

    Check out the complete changelog here.
     
  12. InScatterbrain

    InScatterbrain

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

    Changes:

    • Added the Noise node. It's build around the FastNoise Lite library, which is now included with Map Graph. Check out the FastNoise Lite documentation for more information: https://github.com/Auburn/FastNoiseLite

    • Added a button to switch between a noise data preview and a texture data preview on the Perlin Noise Fill Texture node view.

    Check out the complete changelog here.
     
  13. InScatterbrain

    InScatterbrain

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

    Changes:

    • Fixed issue where the Random BSP Tree node view would throw an exception if one of the node leafs has a width or height of 0.

    • Fixed issue with the "Run on Awake" option, that could cause a crash on startup in standalone builds.

    Check out the complete changelog here.
     
  14. InScatterbrain

    InScatterbrain

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

    Changes:

    • Added Texture To Noise Data node.

    • Made various change to improve multi-threading support, most importantly:
      • Temporary objects are now only removed after all graph processors have completed, this avoids accidentally removing objects that are still being used by other processors.

      • Made improvements to avoid different threads keep processing the graph after exiting play mode, which could cause changes to be applied in edit mode by graph processors that were started in play mode and would cause the editor to freeze when re-entering play mode.

    Check out the complete changelog here.
     
  15. greatkid2009

    greatkid2009

    Joined:
    May 13, 2020
    Posts:
    1
    I have been trying to figure out why this is happening. I keep getting the error "Input port "Draw Color" on node "DrawNoiseThresholdNode" needs to be connected." and it is connected. upload_2023-7-11_12-4-6.png
    Do you have any idea how I could fix this?
     
  16. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Sorry you're experiencing this issue. I haven't seen this happen before, so I'm not sure what's going on.

    You probably already tried this, but please try restarting Unity and see if the problem goes away. If that doesn't work enable the "Skip Checks" option on the runner component. This will ignore the warning and attempt to run the graph anyway. That will probably fail, but an error should be logged that should help diagnose the problem.
     
  17. InScatterbrain

    InScatterbrain

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

    Changes:

    • Improved output consistency when using a static seed, particular using multi-threaded options. More specifically, when a type entry from a (tile/prefab/tilemap) set is randomly picked for placement, it should now be the same every time when using the same seed.

    • Fixed issue where the "Port is unconnected" warning wouldn't go away after connecting the affected port.

    • Fixed issue that could cause Unity to crash after stopping the Visual Studio debugger followed by a domain reload.

    Check out the complete changelog here.
     
  18. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    This turned out to be a bug that should be fixed now with v1.21.1.
     
  19. InScatterbrain

    InScatterbrain

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

    Changes:

    • Fixed issue where deleting an item from a list, with focus on the name field, would cause the newly selected item after deletion to be renamed to the deleted item.

    Check out the complete changelog here.
     
  20. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Came to ask this same question, and got it working thanks to this :)

    Just wanted to say thanks.
     
    InScatterbrain and Railon23 like this.
  21. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Now, I do have some questions:

    1- Following the tutorial that places a Player, Similar to how you use the draw circle to avoid placing enemies near the player, How could I define an area (ideally rectangular) where is allowed to place the Player?
    In this example it already uses the floor to place the player, but let's say I don't want to spawn anything on the left or right side, just near the middle.
    upload_2023-10-16_18-13-56.png

    2- Can I define specific places I would want something to happen? for example I want an Island on some specific place at the corner of the map, and let the tool draw randomly whatever on the rest of the map, Or I may want to spawn something at a specific location.
    Let's say I want those red circles locations being input externally, because I want land specifically there, and everything else can be filled randomly.
    upload_2023-10-16_18-17-35.png
     
  22. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    If I understand your question correctly, I think in both cases you'll want to use masks.

    In the first case, you could merge the mask you're creating already, with one that masks off everything but the rectangle you specified. If you always want it to be the same rectangle, you can create an input parameter of the type RectInt[] (you'd need need it to be an array, because the Draw Rectangles node expects one, but you can just put a single element in there) and define the rectangle you'll always want to mask off. Then you can draw the rectangle using the Draw Rectangles node and create a mask out of it, that you can then merge with the one you already have. Alternatively, you could also provide a texture for the rectangle mask and pass that through an input parameter (or even constant node if you prefer) instead.

    Please note that if you mask off a big section of the map like that, that you can end up with scenarios where there's no valid space left to spawn the player. Depending on your situation that may or may not be a problem, but if it is you'll either need to make sure that the player gets spawned no matter what, or you'll need some kind of check after map generation has been completed, to see if it's valid (and generate a new map if it's not).

    The solution for the second case would be similar. You can pass a Vector2Int[] (again an array) for your circle centers and use that to draw the circles for your mask or you could pass a texture that you can use as a mask.

    Does this answer your question?
     
    daville likes this.
  23. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Yes, perfect! Thank you, I just did a test and this is what I needed.

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

    One more question, I want to place few points (like 6) but I want them to not be close to each other for at least some min radius.

    How could I make sure that happens?

    The only way I can think of how to do that would be quite long, something similar to this but 6 times longer. Because I would use the end of the first point to create a circle mask and joint it with the previous masks and then create another point, and do that 6 times.

    Probably I'm overthinking this and there's an easier way.

    upload_2023-10-17_15-24-4.png

    Basically, I want from 1 to 6 points, randomly placed within that rectangular area, but also not too close to each other.

    The situation I want to avoid is this:

    upload_2023-10-17_15-31-6.png

    where if I place the 6 points, sometimes they could be next to each other
     
  24. Railon23

    Railon23

    Joined:
    Jan 30, 2014
    Posts:
    32
    On the discord there´s the custom-nodes channel. One user created the "Drawing points with circular distance to each other" node. I guess that´s what you need :)
     
    daville and InScatterbrain like this.
  25. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    Alternatively, you can use the Random Rectangles node (it can take a mask as input) and get the Rectangle Center Points and draw those points.

    I think the custom node uses a radius to determine the distance between point placement, so it's more precise. The rectangle approach might be good enough for your situation though, if you prefer to stick to nodes that are officially supported.
     
  26. InScatterbrain

    InScatterbrain

    Joined:
    Mar 7, 2017
    Posts:
    234
    daville likes this.
  27. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
  28. InScatterbrain

    InScatterbrain

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

    Changes:

    • Added list of output parameters to the graph runner inspector, which shows the string representation of the latest output values.

    • Fixed issue with the Generate Area Graph node, that would throw an "No Delaunay triangulation exists for this input." exception, if the areas provided have centroids that can be part of the same straight line.

    Check out the complete changelog here.
     
  29. InScatterbrain

    InScatterbrain

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

    Changes:

    • Fixed issue where the Random BSP Room node would throw an exception when a room's width or height is smaller than 1, on newer versions of Unity. A room's width and height now has a minimum of 1, whenever possible.

    Check out the complete changelog here.
     
  30. InScatterbrain

    InScatterbrain

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

    Changes:

    • Added Merge Point Pairs node.
    • Added Random Points Per Area node.
    • Added option to add custom styling to the graph editor, by adding a MapGraph.uss file to a Resources folder in the project.
    • Fixed issue where lists with exactly two items wouldn't get randomized correctly.
    • Tilemap bounds are no longer compressed at runtime by Map Graph. Tilemaps should now be compressed beforehand in the editor instead.
    • In addition to the position, the zoom level of open graph editor windows now also get restored, when the domain gets reloaded.
    • Fixed "Connected Caves (Cellular Automata)" subgraph, so that it now works with either a texture or a size as input.
    • Fixed issue where current position in a graph editor window wouldn't get restored on the first domain reload after the window was opened.
    • Modified the AreaGraph class so that it doesn't directly inherit from the UndirectedGraph class anymore. This makes it possible to refer to the AreaGraph class in a custom node without requiring a reference to the QuikGraph assembly.
    • Sample Project: Added the "Roguelike Map" example.
    • Manual: Added the "Custom styling for the graph editor" page.
    • Manual: Added the "Editor-only" section to the "Creating your own node views" page.
    • Manual: Added a section on the Troubleshooting page about fixing 'The type or namespace name 'Editor' does not exist in the namespace' errors.

    Check out the complete changelog here.
     
    Gekigengar likes this.