Tree instances

When I set the color of an tree instance the tree just becomes completly black and lost the texture it had.

Please allow me to recommend an alternative solution.

I have used tree instances in the past, and I have also found it to be more useful to instantiate the tree objects by using a script which finds where the trees have been placed and places an actual Game Object there.

There is then a simple way to determine the colour of the instantiated tree. It is the following line of code, placed in the indicated space in my instantiation script.

myNewObject.renderer.material.color = Color.red;

To instantiate the object, use this code. If it doesn’t work the way that you want it to, there are several tutorials about instantiation online.

//Variables
var treeFab : Transform;
var grabTerrain : Terrain;
var trees : TreeInstance[];
 
function Start ()
{
	Instantiate();
}

function Instantiate ()
{
	//For when i is worth zero, i gets the tree instances data on the terrains and their lengths
	for (var 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;*
  •  var myNewObject = Instantiate (treePrefab, pos, Quaternion.identity);*
    

//Input the colour code here
}
}
Please inform me if there are any problems.