Accesing Terrain Trees

Is it possible to manipulate the trees that are part of the terrain system? For example, would I be able to determine through script, the number of trees in a given area. Furthermore, would I be able to remove/add trees, through script, where they would be a part of the terrain system (ie. they are billboarded and swayed the same as all the other trees)?

Technically no, there is no functionality exposed officially.

Inofficially: check out the Terrain Tools

Yes, that is possible through unofficial API calls.

Check here for an example I came up with, including code that you could probably hack up for your own use:
http://forum.unity3d.com/viewtopic.php?t=30618

Thanks, Tom. By the way, where does one learn about those unofficial API calls? I knew there had to be a way to access the tree data, since the editor can paint them in, but where do you start to find out about that sort of stuff?

nowhere, cause inofficial means its not supported nor documented.

people got it through reflection out of the dotnet assemblies cause they know the editor use it so it must be there (the editor code is equal to ours)

dreamora is mostly right. I’ve used reflection, a lot of experimentation (because sometimes reflection doesn’t tell you what the parameters mean or how they work) and of course of lot of stuff that other people found out before.

Also, the Unity people are very helpful on the forum, even with unsupported API calls, if you got far enough to come up with a specific question. So thanks to them.

http://forum.unity3d.com/viewtopic.php?t=45718

This script shows how you can access the terrain trees data and change tree properties. remove/add trees can be done by removing / adding treeInstances with full control over the tree position.