Mass Tree Scaleing

So I need to scale the trees that are placed using the Mass Tree Placement feature.

So far I have this script:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public class ResizeTrees : EditorWindow {
	
	[MenuItem("Terrain/ResizeTrees")]
	public static void ShowWindow()
	{
		EditorWindow.GetWindow(typeof(ResizeTrees));	
	}
	
	void OnGUI()
	{
		GUILayout.Label ("Resize Trees", EditorStyles.boldLabel);
		
		if (GUI.Button (new Rect(10, 10, 30,30), "Resize Trees"))
		{
			//List<TreeInstance> newTrees = new List<TreeInstance>(Terrain.activeTerrain.terrainData.treePrototypes);
			List<TreeInstance> newTrees = new List<TreeInstance>(Terrain.activeTerrain.terrainData.treeInstances);
			
			for (int i = 0; i < newTrees.Count; i++)
			{
				TreeInstance ti = Terrain.activeTerrain.terrainData.treeInstances[i];
				
				ti.heightScale *= 2;
				ti.widthScale *= 2;
				
				
				
				// Re asign it
				Terrain.activeTerrain.terrainData.treeInstances.SetValue (ti, i);
				//Terrain.activeTerrain.terrainData.treeInstances[i] = ti;
			}
			
			Terrain.activeTerrain.terrainData.RefreshPrototypes ();

		}
	}
}

The commented out lines about assigning the tree instance back in both have the same effect, nothing changes and no errors.

Just wondering if i’m missing something obvious. Thanks in advance.

I think you may need to call Terrain.Flush() to actually update the terrain. Not sure if this is still the case though.

Upon further investigation a simple flush was not the sole issue. Here’s some working code.

        void OnGUI()
        {
            GUILayout.Label ("Resize Trees", EditorStyles.boldLabel);
           
            if (GUI.Button (new Rect(10, 10, 30,30), "Resize Trees"))
            {
            //List<TreeInstance> newTrees = new List<TreeInstance>(Terrain.activeTerrain.terrainData.treePrototypes);
            TreeInstance[] newTrees = Terrain.activeTerrain.terrainData.treeInstances;
               
            for (int i = 0; i < newTrees.Length; i++)
                {
                newTrees[i].heightScale *= 2;
                newTrees[i].widthScale *= 2;
                   
                // Re asign it
                Terrain.activeTerrain.terrainData.treeInstances = newTrees;
                //Terrain.activeTerrain.terrainData.treeInstances[i] = ti;
                }
               
            Terrain.activeTerrain.terrainData.RefreshPrototypes ();
			Terrain.activeTerrain.Flush();
            }
		}