0

When implementing a large hexagonal grid (256x256) of tiles in a Unity game, the game becomes very slow and hardly able to function. The hexagons are in a prefab. A script controls the size of the grid and the spacing between each hexagon. How does one go about rendering a 1024x1024 grid of Unity objects?

When the game is built on Win64 it is also still quite slow.

This is an image of hexagons rendered:

https://i.stack.imgur.com/4bU3r.png

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
nate6631
  • 1
  • 4

2 Answers2

0

Try making the grid elements static and make sure static batching is turned ON in player settings. This will optimize their rendering significantly. You probably should even go as far as combining them all into a single mesh (see tools like this one for that purpose).

If you can show us the actual scene hierarchy and the actual structure of your grid nodes then we can help even more.

Clay Fowler
  • 2,059
  • 13
  • 15
  • I did the static thing for all objects, and made sure that setting was on. It did help performance out a little, I can tell. I should have probably stated that I'm generating these nodes via script at runtime.Someone suggested to me a few minutes ago that I should have a hexagon grid on a single plane and raycast to it. Then find the local coordinate of the hex and make some sort of overlay. That would make it faster and optimized, but it wouldn't let me access the hexes like I wanted to. – nate6631 Aug 24 '15 at 04:35
0

Because of how Unity works, non-static objects have a tendency to get heavy - they each end up with their own transforms and end up getting drawn even when they're not on screen.

It's the reason more minecraft clones aren't seen coming out of Unity.

If you can't set the hexagons to static for some reason (i.e.: creating procedural levels etc), you'll have to perhaps simulate the hexagons through creative shader manipulation (like saving each mesh into a single array of vertices with a second that tracks a corresponding mesh id) or by writing a script that creates/adds vertices and faces to a single mesh on a single game object.

You may also speed up the scene by creating smaller levels and loading/unloading them as the player moves towards them. See: Application.LoadLevelAdditive

Aaron Hull
  • 422
  • 4
  • 16
  • Yeah that was another option (shaders). I really won't lie, I don't have much experience with shaders, nor could I write my own. This would really be the way to go wouldn't it? – nate6631 Aug 24 '15 at 16:49