Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Procedural Hexagon Grid Framework

Discussion in 'Assets and Asset Store' started by Hyttjo, Mar 17, 2015.

  1. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17


    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.
     
    Last edited: Nov 22, 2018
    Sinue and EliasMasche like this.
  2. lavagin

    lavagin

    Joined:
    May 30, 2013
    Posts:
    2
    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.
     
  3. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi, thank you for your interest.

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

    2. 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 Started Guide.pdf

    3. 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.

    4. 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.

    5. 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.
     
  4. roh032

    roh032

    Joined:
    Sep 6, 2014
    Posts:
    4
    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.
     
  5. zylv3r

    zylv3r

    Joined:
    Dec 31, 2014
    Posts:
    1
    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
     
  6. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi,

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

    Best regards,
    Jouni Hyttinen
     
  7. mojimm

    mojimm

    Joined:
    Aug 2, 2015
    Posts:
    2
    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
     
  8. mojimm

    mojimm

    Joined:
    Aug 2, 2015
    Posts:
    2
    will you consider to make a map editor to create new map manually or edit the saved maps in the future?:)
     
  9. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    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
     
  10. Sx3

    Sx3

    Joined:
    Sep 25, 2012
    Posts:
    6
    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
     
  11. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    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 :)

    Best regards,
    Jouni Hyttinen
     
  12. Auger

    Auger

    Joined:
    Jun 30, 2014
    Posts:
    9
    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 :)

    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.
     
  13. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    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
     
  14. Sinue

    Sinue

    Joined:
    Nov 16, 2015
    Posts:
    2
    Hi,

    I bought this asset some days ago and I am really impressed! Good job :)
    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
     
  15. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi Sinue!

    I'm really glad to hear that you like this asset! :)

    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
     
  16. Sinue

    Sinue

    Joined:
    Nov 16, 2015
    Posts:
    2
    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. :)

    Greetings Sinue
     
    Hyttjo likes this.
  17. Auger

    Auger

    Joined:
    Jun 30, 2014
    Posts:
    9
    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.



     
    Last edited: Nov 26, 2015
    Hyttjo likes this.
  18. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    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 :)

    Best regards,
    Jouni Hyttinen
     
  19. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    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!
     
  20. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    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
     
  21. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    Thank you very much for such a fast reply! I will definitely buy your product. :)
     
  22. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    Hi, I've bought your asset, but there are three identical errors that immediately pop up once it's imported:

    Assets/ProceduralHexGrid/Scripts/NoiseManager.cs(3,7): error CS0246: The type or namespace name `LibNoise' could not be found. Are you missing a using directive or an assembly reference?

    They all point to these three lines:
    using LibNoise;
    using LibNoise.Generator;
    using LibNoise.Operator;

    Could you please help me out with fixing these errors?
     
  23. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi Sartoris,

    please follow installation instructions in the readme file :)

    Because of Unity Asset Store rules, LibNoise can’t be included in this product download but it is open source and can be freely downloaded from here: https://github.com/ricardojmendez/LibNoise.Unity/archive/master.zip

    Just extract its contents into your project's asset folder and these error messages will disappear.

    Best regards,
    Jouni Hyttinen
     
    Last edited: Dec 6, 2015
  24. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    Ah, thank you, should have looked at the readme, a rookie mistake on my part. But thank you once again for the lightning-fast response! :)
     
  25. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    Sorry to bother you again, but I have one more question. As far as I understand, in order to generate random maps, one should tick the option Generate Random Seed in the Noise Manager Inspector window. However, when I do this, a random seed is generated in the form of a number in the inspector (let's say 9785), but the new world is always identical, i.e. looks as though the seed number is still set to 0. Should I be doing something differently or changing some other values?
     
  26. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi Sartoris,

    you have managed to find a bug which I apparently was able to introduce into this package in the latest 1.06 version, thank you for that! :)

    Currently you can avoid this issue by first clicking in the GridManager's inspector "Generate Preview Grid in Edit Mode" button couple of times and after that go into Play-mode. This will force Unity to generate real new random seed and you will see different grid every time to be generated. I will find the real reason behind this bug in the next few days and will update the package in the Asset Store. I will inform when this is properly fixed here in the forum post.

    Best regards,
    Jouni Hyttinen
     
  27. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    21
    OK, thanks for looking into it, I'm looking forward to your next update. Hopefully it's not something that will require too much work. Good luck!
     
  28. Skaeren

    Skaeren

    Joined:
    Feb 9, 2015
    Posts:
    14
    G'Day Hyttjo,

    I have several questions:

    1) What sort of manual editing is possible? defining terrain type, river placement, etc.

    2) Does each hex have their own grid coordinate, such as 0,1 or 3, 4 or 100, 50 and so on.

    3) Using this image as a base, how easily could I recreate this map in hex terrain style using your product? http://i.imgur.com/kFd1BMN.jpg
     
  29. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Good day to you too Skaeren!

    1) Initial main purpose for this package was to be only procedural generator of the hexagon grid, but I have received so many requests for manual map editing now that I have started implementing it for the future release.

    2) Yes, every cell has their own X and Y coordinate and has reference for their neighbours.

    3) You can get the generated map to look like in your picture now by combining different noises together and playing with all the other settings but you probably won't achieve exactly the same result as in the picture. My current plan is to implement map loading from the image file so that users can generate the desired map by image editing software easily.

    Hope I was able to answer to your questions.

    Best regards,
    Jouni Hyttinen
     
  30. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi all,

    a bug in the random seed generation has now been fixed in the version 1.07. It will probably take couple of days for the Asset Store to update the package to the newest version.

    Best regards,
    Jouni Hyttinen
     
    Last edited: Dec 11, 2015
  31. gracks

    gracks

    Joined:
    Aug 4, 2014
    Posts:
    8
    I just got this framework, it's cool so far.

    If I wanted the hex heights to be discrete tiers, is there a good way to make that change to your system? I'd like to make it so a hex has a height of 0, 1, 2, etc. with transition hexes between discrete heights, rather than smoothly changing heights between all the faces of all the hexes. So the world would be composed of plateaus, similar to the terrain height variations in something like StarCraft.
     
  32. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi gracks and thank you for your purchase!

    If I understood you correctly, the Voronoi noise could be something that may give you the results you want. It creates plateaus with discrete height intervals. Here is the result when only Voronoi noise is used in the Noise Manager:




    Best regards,
    Jouni Hyttinen
     
  33. needyme

    needyme

    Joined:
    Feb 10, 2013
    Posts:
    8
    Do you have a road map for when you expect the "future release" with manual map editing to be available?
     
  34. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hello needyme,

    This project has been in a little hiatus period lately due to my busy schedule. But I am planning to continue with this soon™

    Best regards,
    Jouni Hyttinen
     
  35. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I've been looking for a good world map generation tool for a while, now, and I'm really interested in this. Great work, @Hyttjo!

    In addition to the editing/heightmap import features other have requested, I'm interested in randomly generating by type. For example, generating a peninsular landmass. Ideally, this would be like an options menu with setting which sides were ocean, etc.

    My end goal is to be able to generate random maps clearly inspired by real-world regions (the English isles, Jutland peninsula, southern Scandanavia, etc) but have enough variance to them that each game is different.

    Additionally, is there a logical way to implement a fog of war system into this?
     
  36. dstoyer

    dstoyer

    Joined:
    Jan 21, 2017
    Posts:
    1
    How can I easily select neighboring hex cells when selecting? I want to determine neighboring hexes for area damage effect.
     
  37. dlandi

    dlandi

    Joined:
    Apr 28, 2019
    Posts:
    1
    Hello. Have there been any updates to this project? Will it work with the latest version of Unity?
     
  38. Hyttjo

    Hyttjo

    Joined:
    Aug 25, 2012
    Posts:
    17
    Hi,

    This was updated half a year ago to be compatible with Unity version 5.6.3 and also added a new HeightMapManager feature for loading height maps from .PNG images.

    Best regards,
    Jouni
     
  39. Vitoy

    Vitoy

    Joined:
    Jan 27, 2018
    Posts:
    1
    Hi, I bought your asset on the store, first of all, great job!
    I would like to use it to create a map with different types of biomes with different relief for some kind of RTS.

    I have some questions:
    - Is it possible to generate one biome at a time and assemble them ? (of course they would have to have a common border height) There would be 7 same sized biomes of hexagonal shape arranged in a bigger "hexagon".
    - How hard and costly would it be to, for example, double the number of triangles un a cell ?
    Note: Those are not requests, I intent to modify the code myself
     
  40. Norm49

    Norm49

    Joined:
    Jun 7, 2021
    Posts:
    12
    Hi i have the same question.

    is it possible to have different hexagon pas sheering border by having same border height?
     
  41. devnullicus

    devnullicus

    Joined:
    Jan 6, 2021
    Posts:
    5
    This link does not work to install the libnoise package (at least in Unity 2021.3.12f1). I've tried various manipulations, but nothing seems to get the package manager to like the URL. Without that, I can't run or compile the procedural hexagon grid framework package
     
  42. Dawndropart

    Dawndropart

    Joined:
    Mar 19, 2022
    Posts:
    1
    So this doesn't work with the current version of unity?