Why does my tree script not work

Hi , so I know another {one} about trees not using scripts because there not actual gameObjects…

So I ended up making a working cut the tree down script… but when I went to mass place the tree prefabs … The script ended up nulling out that goes with the tag reverting back to default instead of " Tree ". So I looked threw the documentation and found terrainData and treeinstantce … so I wrote a for loop and have a loading screen wait untill all the "Fake tree objects are created " meaning just the collider with a tree damage script " Java script "

The problem i’m having now is that … ok it creates the number of trees for treeInstances so if I have 10 trees 10 fake tree objects with collider , if I have 20 ,… 20 fake tree objects suberb … Ok there being made its loading , loading done… HUH! the trees are all at 1 position on the corner of the terrain so I know I wrote the terrain positions array wrong and im not sure so much on how the positions are stored… for the terrain data …

Here is a snap shot of whats happening :
[9024-treeproblem.jpg*|9024]

Here is my script:
//Made by -=BloodyDuskTeam=-
//
//http://bloodyduskteam.ucoz.com/

//This script finds all the terrain's trees then creates the tree object for user interaction for each tree position

var treeFab : Transform;

var grabTerrain : Terrain;
var trees : TreeInstance[];

function Start () {

 			
		for (i=0; i <Terrain.activeTerrain.terrainData.treeInstances.Length; i++)
		{
		
			//var treeInstances : TreeInstance = new Terrain.activeTerrain.terrainData.TreeInstance();
			
		
			
			Instantiate(treeFab, trees*.position, Quaternion.identity);*
  •  }*
    

}

Terrain positions are in the range of 0.0 to 1.0 across the terrain block.

So a line of 100 trees across your terrain block could be coded…

for(int i=0; i < 100; i++)
{
	TreeInstance ti = new TreeInstance();
	ti.prototypeIndex = 0;
	ti.heightScale = 1.0f;
	ti.widthScale = 1.0f;
	ti.color = Color.white;
	Vector3 v = new Vector3(i / 100.0f, 0.0f, i / 100.0f);
	ti.position = v;
	t.AddTreeInstance(ti);
}

Ok thanks to robertu is because is was storing the trees at a local position not, world coordinates … So I wrote a algorithm if anyone is interested. here is the compiled script.

	for (i=0; i <Terrain.activeTerrain.terrainData.treeInstances.Length; i++)
		{
			var terrain : TerrainData  = Terrain.activeTerrain.terrainData;
			var pos = Vector3.Scale(Terrain.activeTerrain.terrainData.treeInstances*.position,terrain.size)+ Terrain.activeTerrain.transform.position;*
  •  	Instantiate(treeFab, pos, Quaternion.identity);*
    
  •  }*
    

I’ve not done much with Terrains, but based on a read in the script reference, you should be able to do something like:

	for (int i=0; i < Terrain.activeTerrain.terrainData.treeInstances.Length; i++) {
     var pos = Terrain.activeTerrain.terrainData.treeInstances*.position;*

Instantiate(treeFab, pos, Quaternion.identity);
}
This gets the positions directly from the treeInstances array. I’m assuming the positions are in world coordinates (since the reference did not say differently), but it is possible they are relative to the terrain.