How does many terrains on scene affect performance?
So, I made a tiny terrain with trees, which I saved as a prefab and want to replicate using script all across the scene (this is just a test for now, I might make a terrain generator using this method). The editor view started lagging a bit after I made a few duplicates:
The question is, how well can Unity handle multiple terrains? Is there a way to optimize those tree patches, or should I stop trying?
What benefit are you trying to achieve from duplicating a tiny terrain lots of times rather than just having a single large terrain, which will allow Unity's inbuilt terrain LOD system to work better?
It'll allow me to generate the map by just instantiating tiny pieces ins$$anonymous$$d of generating texture or trees or modifying height directly. Just easier that way.
Answer by Wolfdog · Jan 06, 2017 at 11:35 AM
Terrain in Unity isn't great for performance. This is clearly visible the larger the terrain gets. Splitting it up into smaller pieces is in fact the way some people have tried to improve performance. However, from what I can see, you will have an insanely large amount of these terrains. This might actually be worse than just one terrain piece, simply because of the number of them. This is similar to trying to render one model with 10,000 faces vs 10,000 models with one face each. The larger model is easier to render.
Increasing the terrain chunk size and simply having less of them should improve performance, and only rendering the terrain chunks visible by a camera should again improve performance significantly (occlusion culling).
If this is the way you want to do it, then you should take a look at methods which convert terrain to mesh, as mesh it easier on performance. There are scripts on the internet which can convert terrain objects to mesh, keeping trees and grass orientated. However, the terrain will lose some detail.
I can remember using TerrainObjExporter in the past, but I don't know whether it will work in real time, or only in the editor, so it might not be what you're looking for.
Ok thanks I think this idea was a bit crazy, I should just use one of the paid terrain generation tools from the asset store, ins$$anonymous$$d of reinventing the wheel.