public void Clear() { // Make all chunks visible before clearing foreach (KeyValuePair <Vector2, GameObject> chunkEntry in terrainChunks) { GameObject chunk = chunkEntry.Value; chunk.SetActive(true); } Transform[] chunkTransforms = GetComponentsInChildren <Transform>(); GameObject[] chunks = new GameObject[chunkTransforms.Length - 1]; terrainChunks.Clear(); int index = 0; foreach (Transform chunk in chunkTransforms) { if (chunk != transform) { chunks[index] = chunk.gameObject; index++; } } foreach (GameObject chunk in chunks) { DestroyImmediate(chunk, true); } if (forestGenerator != null) { forestGenerator.Clear(); } }