- Home /
Procedural TileMap generation without creating gameobject per tile.
I've been searching all over the internet to find a efficient way to create procedural tilemap without creating a gameobject per each tile. There is none, or simply i couldn't find it, because i really don't know how to make a search for it. All the TileMap tutorials i found are creating tiles by creating hunderds of gameobjects. Thus the hierarchy in Unity is expanding uncontrollably.
I'm pretty sure this is not the "right" way to do it. Especially after seeing the new Unity 2D tools that supports tilemaps. Unity made it so, you can create tiles in "one" gameobject, not for each tile.
How to do it in the right way?
Answer by Dave-Carlile · Jun 18, 2015 at 09:33 PM
Create a mesh that contains a quad for each tile - this is a single gameobject.
Create a texture that has all of your tiles in a single texture.
Set the texture coordinates of each quad so they point to the correct area of your tile texture depending on the tile that should appear there.
If tiles can change you'll need some way of updating the texture coordinates/mesh.
This is exact approach that i want to do. That's what i was doing back when i was working with XNA. But i have no idea how to do this in Unity. Are there any tutorials for that? Thank you.
The $$anonymous$$esh documentation does a decent job of explaining how to create the mesh, and references a sample project as well.