What you’ll want to do is turn those into a single int[,] instead of a lot of int[,]'s
To iterate through the layers, use
Something like:
void Save() {
int[,,] details = new int[terrainData.detailPrototypes.Length,terrainData.detailResolution,terrainData.detailResolution];
for (int i = 0; i < terrainData.detailPrototypes.Length; i++){
int[,] theseDetails = terrainData.GetDetailLayer(0,0,terrainData.detailResolution,terrainData.detailResolution,i);
// Combine theseDetails into details[i,,] for later access
}
}
You may need to use detailWidth/Height instead of resolution - I forget if it’s always square or not. Anyhow, hope that helps!
details = new int[data.detailPrototypes.Length,data.detailResolution,data.detailResolution];
for (int i = 0; i < data.detailPrototypes.Length; i++){
theseDetails = data.GetDetailLayer(0,0,data.detailResolution,data.detailResolution,i);
}
for (int n = 0; n < details.Length; n++)
{
data.SetDetailLayer(0, 0, n, theseDetails[n]);
}
and i’m getting this error when i set the details back:
Well you need to actually merge theseDetails into details - and then access them from details, not theseDetails. But lets simplifying things and just use a generic list…
TerrainData terrainData = new TerrainData();
List<int[,]> details = new List<int[,]>();
// GET
for (int i = 0; i < terrainData.detailPrototypes.Length; i++){
details.Add(terrainData.GetDetailLayer(0,0,terrainData.detailWidth, terrainData.detailHeight, i));
}
// SET
for (int i = 0; i < terrainData.detailPrototypes.Length; i++){
terrainData.SetDetailLayer(0,0,i, details[i]);
}