Terrain detail meshes/trees via script?

How do I access the terrain detail section in the terrain data so I can paint it on the ground via script.

I have a script that procedurally generates the terrain by doing a few passes on perlin noise etc etc… and also adding textures, but have no idea how to do the same with terrain objects like trees and rocks in the same way it is painted manually.

I can instantiate them as game objects on the terrain randomly but that takes a lot of power and they don’t have the nice culling stuff the terrain detail meshes do.

I’m sure this has been asked before, but I am having a tough time finding out how to do it.


I believe this is the array that holds the data for the different instances of the trees.

@DeadKenny Could you please share your solution for this?