TerrainCollider updates with the Unity.Physics

Hello, i’m searching for the best way to update terrain heightmaps at runtime and decided to see what’s the performance with the new system versus the old one. I’ve found that using TerrainCollider.Create() versus the old terrainData.SetHeights() is 3-10 slower. Is this the only function through which you can update terrain heightmaps on an entity?

Well now looks like you can update the terrain in realtime

That’s not what i’m looking for. The vid at 37:43 shows an example of synchronizing updates from the editor to a built project. Thanks for the link though. I’m looking for how to update terrain physics once the terrain heightmaps have been updated in game. The TerrainCollider.Create() does allow to build a terrain collider from scratch, but is very slow if used at runtime, which is why i was wondering if there’s parts of the API i am missing which would allow to update the terrain collider much faster.

Here’s the kind of terrain collider i am trying to update:

Probably better on the DOTS forum. That said…

If you are using a terrain you still have to call SetHeights, so using Unity.Physics isn’t going to really help you. Not in any real world game where SetHeights itself every frame would be untenable.

Terrains are not designed for what you are trying to do. Different scales can often change what the viable solutions are. Put your project into the context of a real game and it’s completely untenable. Just pushing that much data to the gpu alone makes it so. Never mind physics and everything else that would be going on in a real game.

What you want is more similar to ocean water simulation. Where the scale of the meshing that has to be done every frame forces it to be done on the gpu.

1 Like

The way you describe to make the system is exactly the way i’ve been developing it, where most of the work is done on the GPU. Right now i’m still using the terrain because that’s how i started the development of this system and moving to meshes is too much of a hassle, because working physics is a lot more important to me right now. The amount of work needed to put into it is also the reason why i’m always looking to streamline the process by looking at what Unity has to offer, without me needing to make additional custom code, hence the interest in the new Unity.Physics. Unfortunately, i haven’t come across anything in Unity which would allow to synchronize terrain/mesh collider data on the massive scale i desire.

I am making an ugly workaround around physics though, which is custom Raycasts/ SphereCasts and BoxCasts specificly for the terrain while leaving everything else up to Unity’s physics. I can already get the terrain data from the GPU to the CPU via AsyncGPUReadback and have already made systems to compensate for the lag that it takes to do so. Since i’m not looking for any fancy 100% accurate physics and just want my characer to not get placed below the terrain it’s fine for my project, however, still, takes a long time to develop.

One solution to your problem might be to use a custom terrain shader: