Heightmap mesh colliders

I am using the example project “Procedural” to make heightmaps. How do you attach a mesh collision model to the heightmap? If you hit test, and then attatch a collider to it, it isn’t attatched after you return to the editor. I have tried attatching the collider and then making a prefab of the mesh while in test mode, but it never finishes making the prefab.

Thanks for any help.

Add a Mesh Collider component to the GameObject and put this snippet at the end of the HeightmapGenerator script inside the GenerateHeightmap function.

GetComponent(MeshCollider).sharedMesh = mesh;

Thanks for the script snippet. It takes like 5 minutes to load the scene, but it works very well (You’ve got to love the PhysX engine).

Is there any way to speed up the loading time?
I scaled the mesh down quite a bit and it didn’t seem to help the loading time much (if at all).

One more question:
When using heightmaps, is there a maximum size that the map can be? I made a huge heightmap, but it only uses about 20% of the bottom-left corner.

Thanks for your help.

The limit for the HeightMap is 65,536 polygons, a 256x256 image (this is a limitation of OpenGL). Richard_B has done some work sewing together a huge terrain using 4 million polygons and you can check out how he’s doing it here.