- Home /
Displaying the tiles of an immense grid over a terrain
Hello fellow game devs.
My friend and I are working on a city builder/empire building game. We have succesfully implemented a grid system that functions entirely through code (the tiles aren't represented by gameobjects) and allows us to snap objects to the position of the tile which is closest to the mouse cursor.
So far so good, however:
We kind of hit a wall when the question of displaying the grid came. Something to note is that we're going to need in the tens of thousands of tiles. Now, we don't want to be able to display the entire grid all at once, so that helps, but we will probably need to display at least a few thousands of those tiles at once when the player goes into "zoning mode", where he can paint zones on the grid that will be tagged as "agricultural" or "residential" etc. This means we need to change the color of individual tiles, since any one tile could be made part of a zone. Something quite similar has been done in Cities : Skylines, which also happens to have been made with Unity.
What we came up with so far
1. At first, we thought of using projectors. We thought a single projector could display a portion of the grid over the terrain (using a rather large grid texture, displaying about 15 square tiles of the grid) where the mouse cursor is, and then individual projectors would be instantiated (and quite possibly pooled) over the tiles that are part of zones, even if they're far from where the cursor is. This of course means an awful lot of projectors if the player creates really large zones, so this method might not be the best. It also means we're going to be overdrawing a lot, by stacking projectors on top of each other.
2. So my friend came up with the idea of having each tile on the map be displayed by a single gameobject. Each and every one of those gameobjects would have a mesh component that would render a plane with a few dozen vertices, so that we can line those up with the height of the terrain and thus not have it clip through the tiles. We could then display any tile that we need and make it whatever color it needs to be, depending on whether it is part of a zone or not. Rendering a mesh is also probably faster than rendering a projector, so there's that. The problem with this is that it's probably not gonna look very good since the tiles are going to be slightly above the ground, so we'll have a sort of paralax effect going on, and I don't know how optimized tens of thousands (probably even well over 100k) of gameobjects will be, even if all they have is a mesh renderer component attached to them. Another problem with this method is that it will require a raycast for every single vertex of every single tile to allow them all to line up with the terrain somewhat properly. This would only be done once, when the game is initialized, but it would certainly add quite a bit of time to the loading screens.
Quick note : I also came up with a workaround that would allow us to simply not display large numbers of tiles (by sort of getting rid of the zones system), and my friend admitted that the idea had potential, but still prefered (and I agree with him) not to give up on that system just yet.
The question
So finally, our question(s) is/are : Does one of these two methods of displaying tiles seem better? What would be some alternatives? How is this typically done in professional titles?
Thank you very much for your time, and we hope to get some good ideas out of this.
Your answer
Follow this Question
Related Questions
Some questions about RTS games 1 Answer
Making A House 1 Answer
RTS Style building help 2 Answers
using Tilemap for 3D RTS game 1 Answer
How to Place a Game Object in game(Place a building) 0 Answers