Just want to show this little thing I’ve been working on: A tilemap generator (one elevation level only), which generates a grid of tiles and populate it with procedurally generated terrain based on script settings.
Joel: Yeah the tiles get instantiated. Each terrain type is stored in a prefab, so essentially any prefab could be instantiated procedurally.
In a large grid and / or depending what platform you are targeting, you’d probably want to combine the tile meshes after generation into one big. I’m not doing that at the moment, since I plan to use the individual tiles for a lot of game specific logic, and since I’ll be developing for PC, I’m thinking it probably won’t be an issue. In any case though, right now the tilemap is very inefficient. I haven’t used texture atlasses and such, so it’s quite performance draining at the moment.
One of my initial attempts at procedural terrains also instantiated each and every tile… There is a significant overhead in doing it like this, since Instantiating a game object is a fairly heavy process… having them in-game isn’t so bad, but Unity takes it’s time creating these objects, so if you create, say, a 20x20 tile grid, you’re asking unity to spawn 400 objects at a single pass, and that will lag the thing…
You can try either putting the tile-spawning routine in a coroutine, yielding it after a certain time lapse or a given amount of tiles added, or create a purely numerical map of terrain attributes, and generate a mesh of sorts to conform to that map.
You can still get the individual tile even from an all-emcompassing mesh, by raycasting and int-dividing the hit’s global position for it’s tile coordinates… then you can do whatever operations are needed, and refresh the mesh again
This looks like something i was working on a while ago. I used cellular automata though to create fields of dirt etc. just to make the levels more random.