I have a map with terrain and grass
When i add a building on it, i would love the grass to disappear under (because else, the grass appears in the building :p)
So i implemented this
private void CutGrass(Vector3 buildingCenter, int size)
{
Vector3 terrainPos = terrainManager.ConvertToSplatMapCoordinate(buildingCenter);
int[,] map = terrain.terrainData.GetDetailLayer((int)terrainPos.x - size / 2, (int)terrainPos.z - size / 2,
size, size, 0);
// For each pixel in the detail map...
for (int z = 0; z < size; z++)
{
for (int x = 0; x < size; x++)
{
map[x, z] = 0;
}
}
// Get all of layer zero.
for (int i = 0; i < terrain.terrainData.terrainLayers.Length; i++)
{
// Assign the modified map back.
terrain.terrainData.SetDetailLayer((int)terrainPos.x - size / 2, (int)terrainPos.z - size / 2, i, map);
}
}
This code works quite well
Like this, whatever are the layers under the building, the grass disappears… until…
until the grass index is too high
When i m creating my grass at the beginning, it seems that if i have more grass initial objects than the number of layers, the other ones are not disappearing
For example
If i have 3 layers of ground (rock, dirt and green)
and i have 5 type of grass (generally these are png that i add as billboard a bit everywhere)
and then i put a building somewhere
Only the 3 first type of grass under that building would be removed (it means, every instance of these 3 types would be removed which is good, but not the 2 others)
the 2 next, they stay
AND THAT IS ANNOYING
So if you have any idea how to remove ALL the type of grass, i would be really pleased
Sorry, now i understand what you are saying, you have set up layers for certain objects, and your trying to exclude all 8 of them. Ill replicate this with your code when i get a chance…
Could you please post a full c+ scipt of it? Sorry to ask but im autistic and have a hard time with scripts. I have a buildable asset I use, but it never removes the grass from under the placables. ive been searching for a way to do this for months now