- Home /
Hexagonal Grids
I am trying to build a strategy game based on hexagonal maps. Most hexagonal grids I found are based on the logic of tiling and instantiating single-hex-prefabs into a pattern to form the hexagonal gameboard. This seems to me like a waste of resources ? 20x20 grid would give me 400 GameObjects, which I think is silly ?
Another way people mention would be to use light cookie projectors. How would I go about dynamically coloring individual tiles when I want to show a path, or border ? I'd have to render the cookie texture procedurally ? Is this difficult + slow ?
And the final idea I found would be to procedurally create hex-planes ( let's say 20x20 ) and then stich the planes together to form a large map. 20x20 would be one single mesh - seems to me like a really optimized draw-call method. But I am totally confused about texturing individual hexes in such a mesh ? How would I dynamically change colors of a single hex , or hide/show individual hexes in such a single mesh ?
So my question is: Are there more methods that I don't know about ? What would be the most efficient - most mobile-friendly way of creating a hexagonal grid ?
A 20x20 grid does equal 400 tiles, but it does not (necessarily) equal 400 draw calls. The amount of draw calls is deter$$anonymous$$ed by how many materials are used. If you have a texture atlas which contains all textures for all tiles, you can get a 400-tile grid for 1 draw call. $$anonymous$$anipulating individual tiles is also easy, because they are all individual objects.
Have a look at these links:
Unity: Optimizing graphics performance Unity: Practical Guide to Optimization for $$anonymous$$obiles
So, what would be a benefit of rendering 20x20 into ONE mesh versus the way you describe it - just have individual gameObjects grouped into one parent ? Or would there be one at all ?
Answer by nesis · Jan 15, 2014 at 02:06 PM
If you're worried about memory overhead, you can just create a script that handles an array of particles that will render directly without much overhead at all. This will still give you control over material too.
For even more memory efficiency, instead of swapping materials to change a hexagon's look, you could make a texture atlas and pack it with the different hexagons as needed. So instead of changing material, you just change the given hexagon particle's UV coords.
Can I change hexagon's UV coordinates when the hexagon is a part of one big mesh ?
Yep, you just need to change the UVs of the vertices in question. As far as I know, a mesh's UV array is mapped one-to-one with its vertex array (rather than mapping one-to-one with the triangles array), so to avoid affecting surrounding hexagons, you'd need to generate 6 vertices per hexagon, rather than sharing them across touching hexagons.
Anyone with more knowledge on this aspect feel free to jump in...
Answer by Nick4 · Jan 15, 2014 at 10:55 AM
I'd go with line renderer.
Not a good choice, how would you flood-fill the hexagon with a color ?