Tree Colliders when placing trees at run-time (36921)

I’m generating terrain and then replacing the entire terrain.TreeInstances array with a new array of trees at runtime. Everything seems to work ok except that the trees lose their colliders. If I stop the game and go back into the editor, then turn off dynamic terrain generation and start the game again, the colliders will be there. If I then stop, turn on dynamic terrain generation again and start the game, the new trees won’t have colliders, and there will be invisible colliders where the old trees were in the editor. It seems like Unity must pre-cache the tree colliders somewhere and never updates them during runtime if you change the terrain or trees. I’ve tried including terrain.Flush and terrain.RefreshPrototypes in a few places hoping that would help but it doesn’t seem to. Does anyone have any ideas?

Calling TerrainData.SetHeights after placing trees does the trick.

If you create new TerrainData, think, you forgot assign this new TerrainData to TerrainCollider:

myTerrain.GetComponent<TerrainCollider>.terrainData = myNewTerrainData