This is copy paste from a G+ post that’s been largely ignored, sadly. So I am posting here in the hope that maybe someone will pay attention and possibly step up to help or point me in the right direction.
The TLDR version: Debug.Log(t2ATerrain.terrainData.GetHeights(0,0,w,h)); with t2ATerrain as a valid terrain object, and valid height and width values in h and w, is returning “System.Single[,]” instead of any actual data. I’m using Javascript. What am I doing wrong, and how can I correctly manipulate terrain data during runtime so that I can mirror terrain objects?
Original posting on G+ follows, which includes my original code, and the link to Unity Answers thread for the sake of following the whole issue.
I’ve been trying to poke this to get terrain data, in an effort to be able to mirror terrain for the purpose of endlessly looping it during runtime. Anyway, the important thing is that I can’t seem to get any data on the terrain at all using GetHeights().
In short, when I run this javascript on an empty game object:
var terrainBase : TerrainData; //original terrain data, editor set.
private var terrain2A : GameObject;
function Start () {
var t2ATerrain = terrain2A.GetComponent(Terrain) as Terrain;
var h = t2ATerrain.terrainData.heightmapHeight;
var w = t2ATerrain.terrainData.heightmapWidth;
Debug.Log("h = " + h);
Debug.Log("w = " + w);
Debug.Log(t2ATerrain.terrainData.GetHeights(0,0,w,h));
}
I should, according to the docs, be getting the heightmap as a float array.
It’s not clear what I get it back as actually, but some research with google says it should be a two dimensional array of floats. Maybe. Honestly I mostly found others that were also stuck and some vague stuff about buying some plugin off the store for an example of accessing the data (which smells to me of scam and I cannot afford anyway.) Nothing too useful. No one seems to have posted a straight answer to this issue.
In any case, I should not be getting a “System.Single[,]” as my return.
Yet that is exactly what I get, and any attempts to manipulate the data result in an Out of Range Exception error. Unity appears to be giving me a blank array instead of the data.
I’m guessing this isn’t “Broken Beyond Belief” since it’s a pretty commonly used system, and that this is just user error on my part due to the lack of documentation how to use the commands or what they really return.
The unity questions thread has been less then helpful(only one reply from someone who didn’t get back to me after I responded). But I’ll link it here anyway for the sake of completion. If you respond here instead, I’ll just do the responsible thing and answer my own question there.
Anyway, I’d really appreciate any further info you have to share on this. The docs are really light on how this object works, despite numerous docs and tutorials teaching users to use the built in terrain objects(but suspiciously none teaching much about actual manipulation or, in this case, creating flipped axis clones).