- Home /
Mass place trees scale issue
Hello there
I was wondering if anyone knew a way to scale Mass placed trees in the Terrain functions. I am able to scale the trees when I place them manually on the terrain however when mass placing them they only appear as the default size. Manually placing them would be an option if I could increase the brush size much higher than the maximum setting.
I have tried scaling up the tree prefab but it appears to ignore the scale settings.
any help would be highly appreciated
Answer by AlucardJay · May 24, 2014 at 03:26 PM
Here is a script that will randomly scale between two values the trees that are painted on the terrain.
To set this up :
Create a new javascript named ScaleExistingTrees. Use the code below.
Attach the script to the terrain object.
Drag and drop your terrain into the the Inspector.
Set the min and max scale to your liking.
How to use this :
Right-click on the script component in the Inspector, then a drop-down selection box appears. Example :
Click on Scale Existing Trees, now your trees have been scaled =]
Remove the script from the terrain when you are done.
ScaleExistingTrees.js
#pragma strict
public var terrain : Terrain;
public var minScale : float = 0.8;
public var maxScale : float = 1.2;
#if UNITY_EDITOR
@ContextMenu( "Scale Existing Trees" )
function ScaleExistingTrees()
{
// check if there is no terrain in the inspector, then use the current active terrain
if ( !terrain )
{
terrain = Terrain.activeTerrain;
}
// check if maxScale is less than minScale
if ( maxScale < minScale )
maxScale = minScale;
// variable for storing random calculated scale
var rndScale : float;
// store reference of all the current trees
var treeInstances : TreeInstance[] = terrain.terrainData.treeInstances;
// cycle through each tree
for ( var t : int = 0; t < treeInstances.length; t ++ )
{
// calculate random scale
rndScale = Random.Range( minScale, maxScale );
// apply to curent tree in array
treeInstances[t].heightScale = rndScale;
treeInstances[t].widthScale = rndScale;
}
// apply treeInstances back to terrain data
terrain.terrainData.treeInstances = treeInstances;
Debug.Log( "Scaling Trees Complete" );
}
#endif
Just found this script, helped me immensely after changing my tree model. $$anonymous$$any thanks!!
Answer by vfxjex · Mar 01, 2015 at 12:55 AM
if your tree is procedural, and you don't wan't to deal with scripting, check this out. http://forum.unity3d.com/threads/unity-tree-scaling-inside-terrain-no-effect.98774/