Procedural Hexagon Grid Framework


Asset Store link: http://u3d.as/bn3
Introduction:
Procedural Hexagon Grid Framework has been released on Unity Asset Store and is currently in version 1.3. This forum post can act as a support forum for this package, don’t hesitate to ask any questions about this package and please tell me suggestions how to improve it. I have spent about six month in coding this and I think that this can deliver alot of value for anyone else coding something similar to this.

Basic overview:
This package can be used as a base for RTS, City-building, 4X, Roguelike and Grand Strategy type game or just a procedural level generator for any imaginable type of strategy or action game.

Everything is created procedurally with LibNoise’s different noise algorithms, no pre-made models used at all. Almost everything is customizable with custom editor inspectors. Includes example unit which uses A*-pathfinding to move on the grid, mini-map and plenty of other features.

Additional media:
For more information how to use this and full list of features, please download the readme file: PHGF - ReadMe.pdf

Source code API documentation can be found here: http://proceduralhexagongridframework.gear.host/

Please watch these videos of the end results from the Youtube:

Showcase video

Slideshow video

This package is coded in C# and includes full source code.

2 Likes

Hi there,

I am interested in learning more about your grid framework and I have a few questions.

  1. Can a new map be generated for each new game?
  2. How easily could a map be saved and loaded back again?
  3. 100 x 100 is the max size? There is no way for it to be larger?
  4. How easily would it be to add different terrains. (Your video only really shows water, trees, plains).
    (Cities, bogs, desert, tundra, glaciers, volcanos…etc would be nice)
  5. How easy would it to place graphics on top of the hexes? For instance like a small boat in a hex.

Hi, thank you for your interest.

  • Yes, you can randomize map every time when generating it by using random seed number.

  • There is very good free plugins for that. I recommend using Unity Serializer for saving and loading generated maps for later use. Here is download link for current version (v2.51):
    http://whydoidoit.net/Downloads/UnitySerializer_v2.51.unitypackage
    It is really simple to use, here is instructions for it:
    http://whydoidoit.net/Downloads/Getting%20Started%20Guide.pdf

  • There isn’t upper limit for mapsize. However it will take quite a while to generate big maps like 1000x1000 hexagon cells. Custom inspector editor has upper limit of 100x100 mapsize, but you can define it to be whatever you want by simply modifying the the GridManagerEditor.cs script found in the

  • /Assets/ProceduralHexGrid/Scripts/Editor/* folder location.

Line numbers 36, 37 and 39 define how the Column and Row sliders behave.
Here is example of line 36: GM.columns = EditorGUILayout.IntSlider("Columns: ", GM.columns, 1, 100);
By changing that 100 value to bigger you can define what is the upper limit of the mapsize which you can select from the GridManager’s custom inspector.

Also remember that if you want to see all those hexagon cells at the same time it takes a toll on your CPU performance, but normally this isn’t an issue because in normal strategy games your camera looks from top down a partial view of the game map. I have measured that in my laptop (CPU is i5-4200H), you achieve easily 60fps with 2000 cells in sight which is plenty of game area to be looked at any given time.

  • You can change textures and mesh vertices colorization to gain your specific need for looks. For example you can colorize cells with functions in the ColorizeCells.cs file which can be found

  • /Assets/ProceduralHexGrid/Scripts/Helper/* folder location.

  • I’m not quite sure what you mean by this question. You can easily modify the texture of the cell if you want to place graphic image on top of the cell. Or if you mean by placing a boat on top of water cell that can a unit for example move on top of water. That is allready implemented, you can define can unit move on land, on water or through occupied nodes (such as trees and rivers). Here is an example image of that:

I hope I managed to answer to your questions.

Hi, is in your package some feature like manual edit of map? Or something like load map from previously created heighmap? I need create some hex maps and manually update height of some hexagons and some other parameters.

Hi,

Looks like something I would like to use, I just have one question before buying it; is it fully compatible with Unity 5? if not, when is the compatible version coming out?

Thanks

Hi,

and thank you for your interest. Yes this asset is fully compatible with the newest version of the Unity.

Best regards,
Jouni Hyttinen

Hi,
How about the compatibility and performatnce of this asset on moibles, such as IOS and Android? And is it going to be compatible with win10 mobile in the future?
In addition, the readme.pdf is a little simple, will you consider to write documetation like unity user maual and scripts reference?
Thank you

will you consider to make a map editor to create new map manually or edit the saved maps in the future?:slight_smile:

Hi mojimm,

I’m sorry that I don’t know currently what kind of performance you can expect on the mobile platforms. If it is any help I can give you the performance numbers on my development laptop which has Intel Core i5-4200H CPU:

Size of the grid doesn’t affect performance at all because Unity does draw only what is visible currently for the camera, so only the visible cells matter. Typically in strategy games the view is from top-down so you can’t see the whole grid at once. In my computer when 1500 cells were visible I had 60fps, when 1900 cells were visible I had 40fps and in the case of 10000 cells I had 15fps. My laptop isn’t gaming pc so in better computer those are totally different of course.

I uploaded code documentation to the web, you can find it from the following address: http://proceduralhexagongridframework.gear.host/

It has come into my mind that it could be very useful to be able to edit the generated maps afterwards, It shouldn’t be too hard to develop but I can’t give any estimate when I would be able to start making this feature. I will update here if there is any change in my plans.

Best regards,
Jouni Hyttinen

Hi Jouni,

We are planning to use this in our mobile game but we need some more specs first. Can you tell me something about the number of drawcalls with a grid of about 600 cells? Do you use a terrain or are all cells drawn with their own material? Can you make the entire grid have a hexagonal layout, instead of square (not the single cells but the entire grid)? Are the cells aware of their neighbours?

Regards,
Rogier

Hi Sx3!

Cells use shared material which uses vertex shader for faster drawing. Unity’s own terrain system isn’t used in this package at all. You can choose from 3 different layouts for the grid; Rectangle, Skewed rectangle and Hexagon layout. All cells are aware of their neighbouring cells.

Here are the performance results of drawing 601 cells:

I hope this answers to your questions :slight_smile:

Best regards,
Jouni Hyttinen

Hi Jouni,

I’m new to Unity and C# , I’ve purchased your Hexagon framework and so far I’m liking it. I’m hoping to make a turn based strategy game with it. I might have to bug you a bit here. and there if I can’t figure stuff out :slight_smile:

Anyways, I’ve found a problem that sometimes the hover function where you hover over a cell doesn’t draw the green border around it. seems to be intermittent, since if I change camera bit , it’ll work again. This is with Unity 5.2.2 personal.

Hi Auger!

I’m happy to hear that you like this asset, I will gladly help you with any questions you might have.

I haven’t noticed that behaviour before and I tried to reproduce that on my computer but with no success. My best guess is that it is linked to your Camera setting, here are my current settings and with them everything works correctly:

Best regards,
Jouni Hyttinen

Hi,

I bought this asset some days ago and I am really impressed! Good job :slight_smile:
It is well developed and documented. The last days I played aroung with the asset and next I am trying to add some more environments beside the trees and change everything for my needs.

An editor for editing the generated world afterwards would be very cool.

Greetings,
Sinue

Hi Sinue!

I’m really glad to hear that you like this asset! :slight_smile:

Manual map editing definitely would be a great feature to have. Currently I am pretty busy (untill end of the year) but I have received couple of times this same request so I will be looking into it in the future.

Best regards,
Jouni Hyttinen

Hello,

I found a similar problem and couldn’t sometimes hover some cells. First I thought this is random but my fault was that I added a Box Collider to the Unit Prefab. The collider in default scale is too big and is blocking the raycast (camera to cell). Maybe this will help you to find your problem. :slight_smile:

Greetings Sinue

1 Like

Thanks , I’ll have a look once I revisit my project. I’ve kind of put my project on hold till learn a bit more of Unity and C#. II did manage to get the map working with random textures which was nice. PHG is really well laid out, I learned a lot sifting through the code.

1 Like

Thank you for your kind words Auger! Your modifications to this framework look really fantastic, I hope you can continue soon with your project. It would be nice to see how you progress with it :slight_smile:

Best regards,
Jouni Hyttinen

Hi,

your asset seems very impressive, but I have one question before I make my purchase. Is it possible to add data to each terrain field? For example, if the procedurally generated field is a grass tile, can I set it up so that it contains data such as a number value (let’s say this number represents the amount of food that can be harvested from this tile etc.). I’m trying to build a game with a procedural map, but each tile has to hold some information that can be displayed when the user clicks on a tile.
Thanks in advance!

Hi Sartoris!

yes, it is quite easy to add any additional data to each cell because they are GameObjects so you can write your own MonoBehaviour script, attach it to the cell and this way add more functionality and features to them.

They have by default many values such as height, slope, humidity, wind, moisture and temperature calculated and stored into them. This is done by two separate MonoBehaviour components named CellObject and EnvironmentObject. You can look up the C#-code how these are done and add your own additional data for example into the EnvironmentObject or just write one additional MonoBehaviour component named for example “ResourceObject” and store your resource logic there.

Best regards,
Jouni Hyttinen