DDT script only works on one terrain

Hello Everyone,

I have a dynamic destructible terrain script that works perfectly one terrain I have (the only one in the scene). The purpose of it is to make craters upon collision with my projectile. Unfortunately, when I apply the script to a different terrain inside a different scene, the script fails to work! It is very annoying, as I have fiddled around with the code as much as I could and have not been able to solve this issue. Code:

private var tData : TerrainData;
private var saved : float[,];
var cratertex : Texture2D;
var xRes;
var yRes;
var craterData;


function Start () {
	tData = Terrain.activeTerrain.terrainData;
	xRes = tData.heightmapWidth;
	yRes = tData.heightmapHeight;
	saved = tData.GetHeights(0,0,xRes,yRes);
	craterData = cratertex.GetPixels();
}
function OnApplicationQuit () {
	tData.SetHeights(0,0,saved);
}
function OnCollisionEnter (hit:Collision) 
{
if (hit.gameObject.tag=="projectile")
	{
	var x : int = Mathf.Lerp(0, xRes, Mathf.InverseLerp(0, tData.size.x, GameObject.FindWithTag("projectile").transform.position.x));
	var z : int = Mathf.Lerp(0, yRes, Mathf.InverseLerp(0, tData.size.z, GameObject.FindWithTag("projectile").transform.position.z));
	x = Mathf.Clamp(x, cratertex.width/2, xRes-cratertex.width/2);
	z = Mathf.Clamp(z, cratertex.height/2, yRes-cratertex.height/2);
	var areaT = tData.GetHeights(x-cratertex.width/2, z-cratertex.height/2, cratertex.width, cratertex.height);
		for (i = 0; i < cratertex.height; i++) {
		for (j = 0; j < cratertex.width; j++) {
			areaT [i,j] = areaT [i,j] - craterData[i*cratertex.width+j].a*0.01;
		}
		}		
	tData.SetHeights(x-cratertex.width/2, z-cratertex.height/2, areaT);	
	}
}

I appreciate your help, in any coding language except Boo.
-Hyperion

Erm DUDE. You are going to hate this :stuck_out_tongue:

I deleted the terrain in the project and stuck my own in to it. I put the same scripts on it as the example and put the same figures in and…well it just worked. The only thing that was different was the actual crater texture which just came out black, but the deforming worked and everything. But just as I said in my first comment… the original terrain had lots of height. A generated terrain has very little height.

I changed:

Terrain Height,
Terrain Width,
Terrain Height,
Heightmap resolution,
Detail resolution,

And it still worked.

EDIT: I changed everything in the terrain. It all just worked.

So, my answer, Make sure your scripts are in the right order and the numbers are the same (128,128,2). Also make sure Splat Alpha 0 is in the correct place! Literally copy the example! But most importantly make sure your terrain is not at the lowest height!