- Home /
Terrain trees or GameObjects?
I'd like to implement a system that simulates trees growing, reproducing / planting new trees and allows trees to be chopped down by the player.
Using Unity's terrain trees, I would create some kind of tree manager script that takes care of growing, adding and removing trees and updates the TerrainData.treeInstances array accordingly. For trees being clickable (and mouse-overable), it would likely also have to spawn GameObjects with invisible colliders on the terrain which then remember the index of their correspending TreeInstance. Alternatively, I could just put trees as separate GameObjects on the Terrain. For context, I have some Settlers-style simulation/RTS game in mind.
Does anyone an idea which version would do better performance-wise?
The cons of using Unity's terrain trees so far are that tree visuals could not be generated (can't create new tree prefabs at runtime) and the code might be a bit clunky having to manage colliders that are connected to tree instances somewhere on the terrain.
How many trees are you talking about? hundreds, thousands or more If the number stays reasonable I would use game objects and possibly deactivate them when not in view to save performance. (http://docs.unity3d.com/ScriptReference/Renderer-isVisible.html)
Here is a large forum thread that covers some of the aspects you are considering : http://forum.unity3d.com/threads/using-tree-gameobjects-vs-unitys-built-in-system.183224/
Thanks for the links! A few thousand trees would be nice to have...