Hi all,
I have a editor script to help our level builders place trees with specific densities, restricted to certain areas, etc. It worked in 2.6, but in 3.x it appears that using Terrain.AddTreeInstance(which appears to only recently have become documented) causes the terrain to not respect the TreeInstance’s color field (as it does when “painting” using the traditional inspector) and trees created by the script appear all black (as though they don’t follow the shader naming conventions mentioned here). Is this a bug that’s new to 3.x, or am I creating trees incorrectly? The core of the tree placement script follows:
Terrain terrain = (Terrain)GameObject.FindObjectOfType(typeof(Terrain));
tempInstance = new TreeInstance ();
tempInstance.prototypeIndex = 0;
tempInstance.color = Color.white;
tempInstance.heightScale = 1;
tempInstance.widthScale = 1;
tempInstance.position = new Vector3 (Random.value, 0, Random.value);
terrain.AddTreeInstance (tempInstance);
terrain.Flush ();
The only differences in the actual code is that prototypeIndex isn’t hard-coded and goes through all the tree prototypes, placing as many as needed. As I said, “painting” trees causes them to appear normally, and the trees appeared normally in 2.6, so I don’t think it’s a problem with the model/material, but the docs on modifying the terrain are a bit scanty.