Terrain Collider doesn't update/ how to create a new terrain Collider?


I’m trying to create an modify terrains at runtime. So far I’ve donne this:

//Time to create the first terrain based on the template that is in the scene
		tempTerr = Instantiate(TerrainTemplate, new Vector3(2000.0f, 0.0f, 2000.0f), new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)) as Terrain;
		tempTerr.terrainData = Instantiate(TerrainTemplate.terrainData) as TerrainData;
		hMp = generateHeightmap(tempTerr.terrainData.GetHeights(0, 0, 513, 513), new Vector2(513.0f, 513.0f));	
		tempTerr.terrainData.SetHeights(0, 0, hMp);

At the moment the terrain is being created, and I can see the changes to the terrain (created by the generateHeightmap function).
The Problem is that the player falls throught the terrain and stops at the bottom of the terrain(where the old terrain collider was(A flat terrainCollider)).

Bottom line: how do I update the terrain collider? The SetHeights function should do that but it doesn’t.
What can I do? A little/fast code example would be greatly appreciated.

Thanks for your time…

edit: I’ve already tried Flush() but nothing changed.

I’m sorry if I can’t be more helpful, but I believe you need to manually update the terraincollider, based on the new heightmap (never faced this problem so mine is basically a guess).

For anybody looking for help, in v 2017, 2018… to update the TerrainCollider you have to update the heights on the terraindata of both the terrainCollider and the terrain. Seems like there is a copy. Changing the terrain only will update the visualization but not the collider itself.


In v2019 the terrain has been moved to GPU and the API changed, so maybe this doesn’t work. Seems like there is a function to update “dirty” data.