Collision with custom terrain (heightmaps)

Hello everyone!

I have been working on a custom runtime terrain which uses height maps that are render targets. I just paint on them and assign it to the painted texture to the world pos input in its material.

Instead of just raising and lowering height, it pushes the vertices towards or away from the camera view and creates slopes and things like that. (You can see in the pic)

The grid you see is collision. I can’t manage to make the collision fit the height map :frowning:

What I tried-
I added a procedural mesh component and made a mesh from the flat terrain mesh. Then I cached all the vertex locations on begin-play. When I finished painting the terrain, I looked up the pixel data for each vert in the procedural mesh and set it’s value to match. (Quite literally making a mesh from a height-map).
Here I expected the procedural mesh verts to snap to the location values of the corresponding pixel in the height-map, but the whole mesh disappears. It’s also painfully slow when looking up pixel values.

What works well in terms of performance: I can go through every vert in the procedural mesh and set its Z pos to be a random number. When I paint, the mesh updates very quickly. The only problem is when I retrieve the Z value from the height map, it’s soooo so slow.

So in a nutshell, how could I go about creating the collision for the height map? Am I on the right track?

Any push in a direction would be greatly appreciated :slight_smile: