x


Can I modify grass or details on the terrain at runtime?

Can i have opportunity to remove a type of grasslayer via scrpt? for example when my cube collide on a selected type of grass,the grass http://die.Is it possible?

more ▼

asked Mar 17 '10 at 11:55 PM

devilkkw gravatar image

devilkkw
297 7 10 18

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You can use these (undocumented) commands to read and write the terrain detail layers:

// read all detail layers into a 3D int array:
int numDetails = terrainData.detailPrototypes.Length;
int [,,] detailMapData = new int[terrainData.detailWidth, terrainData.detailHeight, numDetails];
for (int layerNum=0; layerNum < numDetails; layerNum++) {
    int[,] detailLayer = terrainData.GetDetailLayer(int x, int y, int width, int height, int layerNum);
}

// write all detail data to terrain data:
for (int n = 0; n < detailMapData.Length; n++)
{
    terrainData.SetDetailLayer(0, 0, n, detailMapData[n]);
}

So, using the above scripts, you would read the layers, edit the values in the array relating to the details at a particular area, and then write the details back to the terrainData.

Because these functions are undocumented, any future updates of the unity engine might change or remove these functions from the API. This means your project may not work in future versions of the Unity editor, and webplayer builds may not work with future versions of the plugin.

more ▼

answered Mar 18 '10 at 10:50 AM

duck gravatar image

duck ♦♦
41.4k 95 152 415

(comments are locked)
10|3000 characters needed characters left

I assume you are talking about grass on the built-in terrains in Unity.

You can modify the terrain at runtime. See this Q&A:
http://answers.unity3d.com/questions/2224/just-how-malleable-are-terrains-really

You can use that functionality to alter where the grass is on a terrain.

more ▼

answered Mar 18 '10 at 10:51 AM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5273
x1521
x159
x110
x57

asked: Mar 17 '10 at 11:55 PM

Seen: 3698 times

Last Updated: Mar 18 '10 at 10:51 AM