I know that undocumented APIs are use at your own risk, if at all, but I was hoping for a bit of help under the hood with the Terrain API.
Since it turns out that each tree type you add to a terrain has a performance impact, I am creating a slimmed down version of our terrain for integrated graphics. As part of that simplification, I want to reassign the tree prototypes of tree instances that are already placed in the landscape. After reassigning all the trees of one tree type to another type, the tree type that was vacated would be removed from the terrain.
The code below successfully accesses the tree prototype index, but doesn’t seem to set it. I was wondering whether there’s either some other function that should be called to set the index, or whether there’s some other update function that needs to be called to refresh the terrain’s contents overall after setting it. Or, maybe in fact that is read-only after the tree instance is added and I’m out of luck.
var fromPrototypeIndex: int;
var toPrototypeIndex: int;
private var terrainData : TerrainData;
for (var i:int=0; i<terrainData.treeInstances.length; i++)
{
Debug.Log("is: "+terrainData.treeInstances[i].prototypeIndex); // this works
if (terrainData.treeInstances[i].prototypeIndex == fromPrototypeIndex)
{
// this doesn't work -- appears to be read-only even thouggh there is a setter function
terrainData.treeInstances[i].prototypeIndex = toPrototypeIndex;
Debug.Log("new: "+terrainData.treeInstances[i].prototypeIndex);
}
}
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(terrainData));