Hex Grids Framework

After messing with this plugin for one day I am little confused about how to use it. Downloaded demo project and every grid there has a parent HexGrid_Main. But there is also HexGridPreset component that I wanted to use for simplicity reasons. The problem is that I don’t know how I am supposed to get hex under mouse cursor. In HexGrid_Main there is function that reads StaticMeshMap but it is not present in HexGridPreset and the grid is visible in game. Anybody know what array should I look to be able to change one tile type and mesh for another after mouse click? And should I use component or HexGrid_Main?

Yes, you are correct, I did not realize this bug was there, but it does indeed have an error when using odd numbers while centered. The problem is it divides an int by 2, and by default rounds down. I will roll out a fix to the marketplace soon, but since that takes a few weeks to process, the fix is also included below. Inside the GridsHex.cpp, you need to replace with the following at line 182

This is the old code, you want to remove this:



if (bCenterGrid)
    {
        xMin = -(Size.Col / 2);
        xMax = Size.Col / 2;
        yMin = -(Size.Row / 2);
        yMax = Size.Row / 2;
    }


The new code you want to use:



if (bCenterGrid)
{
    xMin = FMath::CeilToInt(float(-Size.Col) / 2.0);
    xMax = FMath::CeilToInt(float(Size.Col) / 2.0);
    yMin = FMath::CeilToInt(float(-Size.Row) / 2.0);
    yMax = FMath::CeilToInt(float(Size.Row) / 2.0);
}


To your second message, the hex grids preset is only set up for InstanceStaticMeshes, which is why the staticMeshMap is missing. This is confusing, so I will try to make a second preset which is a static mesh variant. I won’t put the functionality in both to keep them light, so you can choose which design you want. The decision between them is quite tricky, instances are tricky to manipulate but much more performant. The hex grid main has code for getting what is under the cursor via a line trace, but using the “get hit results under mouse” also works on the grid. If you want to stick with the preset, then some of the examples in the demo room are using instance static mesh variants, and it shows how to get the hit results and find the instance ID from it.

Also, I just want to thank you for the feedback, I will be acting on it all, I really want to make this a rock solid plugin, so any thoughts on it are extremely helpful.

Heya, Sorry for the slow response. The way I have designed it is not unsimilar to what has been suggested, though I agree inheritance is a smart approach. Currently there is a GridsCore cpp, which contains all the universal grids code, and GridsHex, which contains the specific hex implementation. The idea was when I built a square grid system, I would just include the GridsCore. Right now though only Hex Grids are supported, or specifically any grid that has 6 neighbours.

I designed it so biomes can be added, but there’s no specific functions to help build them, I seperate the grid generation from the tile generation so that you can build any design of tile seeding system as you needed, and then you just use the grid to place those tiles. You could use things like flood fills and movement ranges to design some seeding systems, and I have used both the A* pathfinding or the Line Draw functions to plot out rivers and roads, which work very nicely. I didn’t want to write a seeding system with it, as everyone will probably have their own methods, and I don’t know any really good approaches. I think if I was attempting it, I might start by giving all tiles a random tile cost, then doing some flood fills, that way the tile cost would cause the flood fills to have a degree of noise in how it expands. The last tiles in the flood fill should be your boundary tiles, and you could pathfind back to the origin to work out what direction to step outwards (I have an example of that in the Rotate Component) knowing what your first step to the origin is, you could flip that direction and walk the other way, do another flood fill, remove the tiles from the previous from the new result, and biome those. I am making this up as I go so this might not be the best approach but I wanted to provide some ideas. Equally you could just pick a random selection of tiles and flood fill those and those become biomes, but they won’t relate to each other if you did it this way.

Is this your plugin on the marketplace? Hex Grids V10.0 in Code Plugins - UE Marketplace

I rolled my own hexagon grid implementation written in C# that I used for a prototype - but before I convert it to UE, I was wondering if your plugin supports mouse-over or click selection of grid coordinates if the hexagon under the mouse is an instanced mesh?

Hi Matt, sorry for the slow response, I keep an eye on the discord but totally forgot about the forum, in case your still curious, yes that is indeed my plugin, I’m about to update the first post with some up to date information. The plugin does indeed support mouse and roll over solutions using instanced static meshes. I would say the plugin is slightly more instanced focused, though I have plenty of standard static mesh systems as well. I have another update planned soon, which is some methods for custom map shapes, and just some general house-keeping. I will update the first post with the info as soon as its ready.

Since you wrote your own code based grid system, I hope you might find mine ok, in hindsight I would have done a few things differently, but due to it being a cpp plugin and any change to the code and unreal totally unlinks and freaks out, I won’t be changing the underlying code so I don’t break peoples setups. However, I update the blueprint side quite frequently.

Updates! I have added a spline system so you can draw paths using more traditional spline visuals, and am in the progress of making a better base hex grids blueprint that is a bit simpler to set up. It’s not too different, but its just cleaner with less junk. Fixed a few bugs in the process as well. Which just an FYI the hex corners slide pin did not work, and some of the return names have been changed to offer better clarity as to what they do. I have changed them using unreal UPARAM option, so it won’t break anyone’s existing setups.

These updates, along with the grid builder example should hopefully be uploaded to epic Thursday, if I can get it up before 4.19 releases it might not get stuck in the big backlog they get during the post-engine release.

Release 4 of the hex grids plugin is live for Unreal 4.18. You can download the new changes, which include:

Spline generation to draw paths
A new default hexGrid blueprint, to be the base for your projects
A runtime map builder setup, so you can build and save custom grids. The setup is very easy too, just add a component to your character, and call the delegates as required.

Bug fixed on the hex corner node, where the slide value was not working correctly.
Some pins got renamed to better describe what they do. (Rename was done using UPARAM meta so it won’t break existing projects)

Very good to see new updates and videos. It would be also great to have some tutorial videos on how to do basic stuff. Like clicking and selecting tile, changing it for other type or moving pawn there. I spent lot’s of time to look for basic stuff and still I am slightly confused. For example I can’t find a function in grid that would tell me where I clicked and on what tile but on the other hand it looks like there is similar function already included in plugin: Demo Room->Line Trace For Grid. Even if I don’t use example project. Maybe there is simple name problem or it can be moved somewhere else because I would rather not use functions called Demo.

Also I don’t know if it is good idea to have compiled functions used in demo and have them in other projects that don’t need them (I don’t know how many of them there is so maybe it’s not a problem).

This is too awesome!
Do also example games exist?