How would I flip or mirror Terrain data during runtime?

I am trying to make a simple endless terrain illusion. Terrains don’t scale at all with their transforms though, so I can’t just use transform.scale(-1,0,0) to pull off making the clones needed for wrapping. So I’m now trying to create the terrain clones during runtime.

But I can’t seem to get anything returned from terrain.terrainData.GetHeights(0,0,w,h); If I debug.log that info, I just end up getting “System.Single[,]” instead of the array data. According to the docs, from what I understand that should be returning a 2d array of the terrain data, and certainly should not be returning an empty array, in any case.

Here’s the full code below. All I get when running this is the debug returning System.Single[,], followed by a IndexOutOfRangeException error. (The indexoutofrange is presumably because I have not gotten the data correctly in the first place) :

var terrainBase : TerrainData; //original terrain data, editor set.

function Start () {
	terrain2A = Terrain.CreateTerrainGameObject(terrainBase);
	//scale 2A along the Z axis
	var t2ATerrain = terrain2A.GetComponent(Terrain) as Terrain;
	var h = t2ATerrain.terrainData.heightmapHeight;
	var w = t2ATerrain.terrainData.heightmapWidth;
	var oTerrain = t2ATerrain.terrainData.GetHeights(0,0,w,h);

function FlipTerrainX(originalArray : float[,],heightmapX:float,heightmapY:float) {
	var nArray = new float[heightmapX,heightmapY];
	for(var x = 0;x < heightmapX;x++) {
		for(var y = 0;y < heightmapY;y++) {
			//flip the x, but leave y matching
			nArray[heightmapX - x,y] = originalArray[x,y];
	return nArray;

I’m sure I am just missing something simple here.

All I want to do is be able to loop and process the array of heightmaps to mirror the terrain for the other 4 versions needed to loop it forever. This error is a bit over my head, however, and searches are not being very helpful since the information I’m getting is very conflicting on if this should even work.

not sure about what in you terrainBase.
Debug.Log w and h in Start function - what they have?

Old I know… but this was all that came up when I was searching for a solution so I thought I’d leave my answer here. Eventually figured it out. See below.

 public static IEnumerator FlipTerrain(Terrain terrain)
        TerrainData terrainData = terrain.terrainData;

        int widthOfTerrain = terrainData.heightmapResolution;

        float[,] noiseMap = terrainData.GetHeights(0, 0, widthOfTerrain, widthOfTerrain);
        float[,] noiseMapFlipped = new float[widthOfTerrain, widthOfTerrain];
        int flipX = 0;
        int flipY = 0;

        for (int y = 0; y < widthOfTerrain; y++)
            for (int x = 0; x < widthOfTerrain; x++)

                flipX = widthOfTerrain - 1 - x;
                flipY = widthOfTerrain - 1 - y;

                noiseMapFlipped[flipX, flipY] = noiseMap[x, y];


        terrainData.SetHeights(0, 0, noiseMapFlipped);

        yield return new WaitForEndOfFrame();