Is there a way to prevent foliage from passing through mesh?

I have a culvature mesh… If it is painted by somewhat big size foliage… it passed through the mesh is there a way to prevent it??

1 Like

Couple ways:

  • you could use collision on the foliage but that’s not possible for landscape-grass. as well you would likely want to be running meshes w/o collision, for performance, and have some kind of logic to check-for and swap out the cheaper meshes for the ones with actual collision as the player gets near them.

  • you could use a material trick or two on this. sample mesh distance fields in the grass/plant material. if you intersect you can either move the mesh far, far away so it’s culled and you never have anything near a mesh to overlap to begin with, or you can math some bendyness and apply to WPO and make the mesh bend away from the other meshs’ distance field. These methods will work for landscape grass as it’s in the material.

  • another material trick is to use a material parameter collection and keep track of the last several locations of the player. use some math and wpo away from the player-locations (like in Zelda).

These guys have a great channel, link specifically to how to move the mesh out of the way: Landscape & Foliage Interaction for UE4 [For 100+ Actors] (Part 1 of 3) - YouTube

These guys can show you how to make stuff work with the player against landscapes, etc. can be applied to what you are using. ref: Creating Interactive Grass in Unreal Engine 4 |

IIRC there are some marketplace solutions that will do the mesh-swap for you, but there are a ton of vids on how to do this as well.


Really appreciate it :grinning: :grinning:

1 Like

My favorite personal trick with landscape grass, at least, is to have static meshes render to the red-channel of an runtime virtual texture.

In my material, I can check distance fields of other meshes and/or compare the object-pivot to that channel of the virtual texture. If it’s 1 (white, or something rendered to it) , then move the mesh -999999 units so it’s culled by the system.

Here is how to render a mesh into the RVT. Make sure you sample-from and render-back-to the same mask-texture. As well be sure to set to Unlit if all you are doing is capturing the mask (cheaper):

Finally, make sure you set the LOD Bias so it renders AFTER other things, like the landscape, etc:

(sorry for the late reply on this technique, I just polished it off last night…)