Drawing a grid

Hello, everyone.

I’m new to Unity and I’m trying to implement a Sims-like room customization. I need a grid of squares, on which to place objects. I would also like to show the grid lines and implement grid snapping.

I’ve looked around the web and these are the possible approaches I found:

  1. Each grid cell is an individual GameObject (plane). Easy to implement with two nested for cycles. Grid lines can be shown easily, since each tile can be textured individually.

  2. The grid is one single plane. A mesh is rendered over the plane. This is probably a more efficient approach than the above one, but how do I display the grid lines texture?

  3. The game is in 3D, but we can look at the room floor in 2D space. I’m wondering if it’s a good idea to pretty much have a two-dimensional array of all of the tiles and calculate the coordinates of each tile. I won’t even need a texture for the grid lines - they can be drawn over the plane, since I will know all of the coordinates needed.

First approach seems costly, but it’s very popular on the web. The second approach is advertised as more efficient, but I’m having doubts that this might be an overkill for me, since I won’t have terrain bumps and such. Third approach - I didn’t see much on the Internet about it, but I have used it in old 2D OpenGL projects of mine.

I’m trying to figure out what is the “Unity way” to do this. A lot of people have mentioned the second approach on the web, but almost no one seems to have spoken of the third one.

I’d be thankful if someone provided some insight on this.

Hey man,
You should check out Honey Hex Framework. Even thou it is a hexbased system their WIP (work in progress) looks extremely impressive and I have been unable to examine it lately so I don’t know if they have finished yet. Very well worth looking at. I don’t know of a square based grid system like it though and a modification to it would probably be pretty time extensive but less than a full rewrite for sure.

It’s a camera based selection system that uses map chunks. Very efficient size and versatility wise.

I ended up using a combination of 1 and 2 - I have a 2D array of grid tile game objects.

Might not be very efficient if your whole world needs to be a map. In my case, only a small portion of the scene will have a grid and I have not noticed any problems in performance.

Will update this answer if something new pops up and makes me take a different approach.