The graph I see in the map graph editor mode is different from the graph at runtime.
It is difficult to determine whether it is correct.
I’m sorry you’re running into some issues. I’ll look into it and I’ll get back to you as soon as I can.
Unity’s hexagonal grids use a offset coordinate system, meaning it uses the same basic 2D coordinates as a rectangular grid, but where the odd rows are offset. (Or columns in your case, because of the swizzle, which I’ll get into with your second issue. :))
Because of this, the shape of a tilemap that’s stamped onto another tilemap, might change due to it being placed on either an even or an odd row.
Take your tilemap’s shape for example:
* *
* * *
* *
If you look at this in a rectangular 2D grid (which basically is the way it’s stored). It would look something like this:
* *
* * *
* *
The issue here is that on a hexagonal grid, that same 2D shape also represents the following shape, when placed one row over, due to the difference in offset:
* *
* * *
* *
So technically, what’s happening here is correct, if you look at it purely based on the coordinates. However, this is obviously not what you want here, as you want to retain the shape of the original tilemap when you stamp it onto another one.
To solve this, I’m adding an option to adjust the coordinates whenever a tilemap is stamped onto another, so that it keeps the same shape, by comparing the offsets of the rows of the original tilemap with the rows it’s placed upon in the target tilemap.
If this sounds complicated, don’t worry about it too much, on your end it will just mean that you’ll have to enable a checkbox somewhere, once this is implemented.
I’m hoping to put up a .unitypackage patch file tomorrow that will contain this feature (though it might be in a bit of an experimental state).
This is because Cell Swizzle is set to YXZ on the grid (to create flat top cells, I assume), instead of the default XYZ. In order to have the preview images match that, the X and Y on those should also be swizzled. I’ll look into adding an option to swizzle the preview textures, for a future release.
I’ve attached a patch to this post. It’s still work in progress, but it should solve your issue.
You can simply download it and then import it by selecting “Assets/Import Package/Custom Package…” and then select the .unitypackage file. (Be sure to backup your project though, in case anything goes wrong.)
Once you’ve imported the patch, you should (hopefully ;)) see that that the proper shape of your original tilemap is now maintained, regardless of which row/column it’s on, when you generate a new map.
There’s still some caveats I need to work out. These will be addressed in a proper release:
- For the tilemap prefabs you use as input: make sure there’s a Grid component on the object itself, with a Hexagon Grid Layout. (Looking at the screenshots you provided, it looks like you’ve got this covered already :)).
- There’s no option yet to switch between the previous behaviour (maintain coordinates) and this new behaviour (maintain offset/shape).
- Tiles are shifted by one, whenever that’s required to maintain the offset/shape. Because of this, it can happen that the output of a Randomly Stamp Tilemaps node has an additional column outside of the bounds provided. As a workaround you can add a border to the mask to avoid this for now.
- If you use a margin on the Randomly Stamp Tilemaps node, it will not yet take into account any shifted tiles.
Please let me know if this solves your issue or if you run into any other issues I haven’t described here.
Hi~Can you make a hexagonal example like the village in the sample?
I feel quite difficult to make it~:face_with_spiral_eyes:
In addition to drawing the margin points, you can also draw the placement points.
The Randomly Stamp Tilemaps node assumes rectangular tilemaps with no empty spaces (like in the village example), so even the empty parts are considered placements, that’s why drawing the placement points should solve this.
I’ll adjust this in the future though, so that it will only place tiles of the tilemap set that are actually filled and place the margin around those points instead.
Up until now, my main focus has been on rectangular maps, but I’ll definitely be adding a hexagonal example.
That might take a little while though, but I’ll gladly help you whenever you get stuck.
So please don’t hesitate to ask for more help when you need it!
I wanted to give a quick update on the release plans.
I’ll be releasing a version 1.1.2 first that will address some of the issues with hexagonal maps in particular.
Version 1.2 is pretty much done (assuming the final tests don’t show any big problems ;)) and will follow shortly after.
Thanks ~ Hope to see examples soon~:)
Map Graph v1.1.2 is now available.
This update mostly addresses some issues with the Randomly Stamp Tilemaps node and hexagonal grids.
Please be aware that the Randomly Stamp Tilemaps node now gives a different output on the Placements port, so that may affected your existing map generators. In order to get the same result as before, you can merge the result from the Placements port and Empty points port together, using the newly added Merge Points node.
Changes:
-
Made changes to how the Randomly Stamp Tilemaps node stamps tilemaps. It no longer stamps the empty tiles within the tilemap prefab’s bounding rectangle, removing any existing tiles at those points.
-
Please note: This change might impact your existing Map Graphs’ output, as these empty tiles are no longer included in the points gotten from the Placements output port. Instead you can now get them from the new Empty Points port.*
-
Added the Empty Points output port to the Randomly Stamp Tilemaps node, containing any empty tiles spaces within the stamped tilemap prefab’s bounding rectangle.
-
Added the “Create/Map Graph/Tilemap Prefab” option to the Create menu, which creates a new tilemap prefab with all the required components, as a more convenient way of creating entries for Tilemap Sets.
-
Added the Map Graph Tilemap Prefab component with a Lock Shape option for tilemap prefabs with hexagonal grids.
Enabling Lock Shape on a tilemap prefab will make adjustments to tile coordinates when it’s stamped onto another tilemap, so that its shape stays the same whether it’s placed on rows with different offsets or not.
More info about this issue in this forum post: Map Graph – Node-based Random Map Generation - #43 by InScatterbrain
- Added the optional “Precise Margin?” input port to the Randomly Stamp Tilemaps node.
Settings this to true will create a more accurate margin outline around stamped tilemaps, instead of the default bounding rectangle, at the expense of performance.
- Added the Merge Points node, which takes two sets of points and merges them together into one set.
After installing v1.1.2 your tilemaps will deform again, because locking the shape is now an optional thing. To solve this, you should add the new Map Graph Tilemap Prefab component to your tilemap prefab and enable the “Lock Shape” option on it.
Also, you can now use the new “Precise Margin?” input port on the Randomly Stamp Tilemaps node to create a more accurate margin around your tilemap placements. Just attach a constant bool node to it, enable the checkbox, and there should be no more gaps between your stamped tilemaps and their margins.
This is an incredibly cool tool and I am keeping an eye on it for my next project.
Question for you and my apologies if it has been answered.
I see that MG can create both prefabs and gameobjects, but is it possible for MG to simply provide metadata
so we can interpret/ modify that before visualization occurs.
The reason I ask is that I have adapted Karcero for my current project (Karcero produces more pleasing dungeons than BSP-style algs). This works well enough, but I transform Karcero memory maps into metadata (VirtualMaps). From there I can apply styling (e.g. Old Dungeon, Lava Dungeon, etc).
I realize this might be a loaded question of course, the various generators of MG would produce different sets of data, but is, or could there be a unique set of data tied to a particular generation alg? Might it be possible for end users to assign the metadata?
Thanks for reading my long, rambling question here
Thanks for the kind words! If I understand your question correctly, then yes, there’s a couple of ways to achieve this.
Actually the data for either tilemap or prefab maps is the same up until the point the data gets converted to either tilemaps or gameobjects by the appropriate nodes. You don’t have to use those nodes, if you don’t want to. Or you could write your own node before passing it on to those nodes.
For example, here’s the final part of one of the example graphs:
You could put your own custom node before the Texture To Tilemap node and manipulate the texture data, or after to manipulate the tilemap data, before passing it to the Copy Tilemap Data node
You could even write your own node to convert (texture or tilemap) data to your own map format, instead of the default tilemap or prefab options. This is a way you could convert the data into the metadata you use for your VirtualMaps instead.
Writing your own node is pretty straight-forward. (There’s a section about it in the manual: https://mapgraph.insanescatterbrain.com/manual/creating_your_own_nodes.html)
Another way to do it, is to output data using output parameters or to manipulate the tilemap or prefabs after Map Graph has finished (there’s an OnProcessed event that gets called every time a map gets generated, that you could hook into).
There’s a caveat at the moment though, namely that the type of variables that can be used as in and output parameters is currently fixed, so at the moment you can’t use your own classes as input or output for graphs (yet!). This is a limitation I want to get rid of sooner rather than later (which shouldn’t be to hard at this point, actually :)). So I could move that up on the priorities list, if that would become an issue for you.
Also, if you want a different styling or theme, you can simple create different tilesets/prefab sets that you can swap out to create different looking maps with the same graphs.
Sorry for the equally (if not moreso ) rambling answer. And don’t worry if this sounds a bit overwhelming. I’ll gladly help you out if you get stuck on something!
I hope this answers your question?
Map Graph v1.2 is now available.
Changes:
-
Improved Map Graph’s inspectors, such that list items such as parameters and named colors can now be renamed and reordered, among other improvements.
-
Added the Scale Texture node, for the up or downscaling of textures, which can be used to work with tilemap grids of different sizes, for example.
-
Fixed bug where the Randomly Fill Texture node’s output mask wouldn’t work, if no mask was provided as input.
-
Added instructions to the manual on how to install the sample project manually, as an alternative to the automatic install script.
-
Added a credits section to the sample project page of the manual, crediting the creators of the assets used in the sample project.
-
Added a missing change to the changelog for v1.1.2: Added optional port for setting the outline’s width on the Draw Outline node.
Map Graph v1.2.1 is now available.
Just a bunch of bug fixes this time.
I’ve had some requests for additional examples for the sample project. So I’ll be working on that for v1.3.
Changes:
-
The graph editor no longer breaks when unsetting a loaded Graph’s Named Color Set, if that graph contains any Named Color nodes. Instead the Named Color nodes’ values get set to “[None]”.
-
Fixed undoing/redoing removing entries from a Tileset type, Prefab Set type or Tilemap Set type.
-
A Named Color node’s selected value now gets correctly restored after undoing the deletion of that particular value.
-
Input components now show a more specific warning when no runner is set or no parameter is selected, instead of showing a generic error.
-
A more specific error is now logged whenever a Tileset type, Prefab Set type or Tilemap Set type doesn’t contain any entries.
Check out the complete changelog here.
Map Graph v1.3 is now available.
Changes:
-
Sample Project: Added RPG example.
-
Sample Project: Added hex strategy example.
-
Sample Project: Added race track example.
-
Added nodes for getting random values, specifically:
-
Random Bool
-
Random Color
-
Random Float
-
Random Int
-
Random Vector2
-
Random Vector2Int
-
Random Vector3
-
Random Vector3Int
-
Added Perlin Noise Fill Texture node, which fills a texture with a Perlin noise pattern.
-
Added Corner Points node, which extracts and outputs the corner points from a set of points.
-
Added Areas To Points node.
-
Added Draw Areas node.
-
Added Texture Size node (useful to get a texture’s size after scaling it, for example).
-
Added extra Width ports to the Draw Outline node for different outline thickness on different sides.
-
Added Connect Diagonals port to the Extract Areas node. If set to true, diagonally neighbouring pixels will be considered to be part of the same area.
-
Added Outer Areas and Inner Areas output ports to the Extract Areas node, to differentiate between nodes that are touching the outer bounds and ones that aren’t.
-
Default width when drawing connections is now 1 instead of 0.
-
Fixed bug where the graph editor would no longer show changes after having switched to another window.
-
Fixed bug where changes to a tilemap wouldn’t get persisted after running a graph in the editor.
-
Fixed bug where the input parameter’s ID would be displayed in the “parameter is not assigned” warning, instead of its name.
-
Fixed bug where the changes to object set (Tilesets, Tilemap sets, Prefab sets) entries wouldn’t get persisted.
-
Implemented a workaround for a bug in the MIConvexHull library that would trigger a ConvexHullGenerationException in the Generate Area Graph node.
Great, I saw the hex strategy example, it takes some time to learn, thank you~;)
I hope it helps!
Let me know if there’s something that needs more explanation.
Hi!I want to ask some question.
Some time I want to reuse some small graph,But I do not see sub graph implementation.
And I want to draw single rect or point but no node can do it.(For example: Hero reborn point)
If you have some good method please tell me!
Thanks!