Below is a training video from Epic Games regarding Foliage.

https://youtu.be/3ispyNxpRyg

Alternative Solutions - Sander Vander Meiren

Below is a video of an interactive foliage system in Unreal Engine 4

https://vimeo.com/201269628

This is not a node by node tutorial, but rather is the thought process. It is a fully-fledged solution that requires optimization and improvements.

Physics

Most of the solutions already in Unreal Engine are vertex shaders based on distance fields. This looks good on small foliage types (e.g., grass) but not good on larger foliage types (e.g., bushes). A solution was presented by user *Crocopede* on the Unreal Engine forums; using the physics asset tool (PHAT). By rigging and skinning foliage types for reaction, then calling those skinned meshes in a blueprint that simulates physics (turned on), however additional tweaks are necessary.

When using this method you are unable to use the foliage painting tool. This serious drawback creates issues for updating a level. An additional problem is that if you use the world transform data of each foliage component, finding the instanced mesh components is difficult. Using overlap detection only returns the actor and not a single instanced component.

Solutions

You can get the component from a “break hit result” node after raycast. On every tick, do a “multi sphere trace by channel” and break the hit result. You will get the index number and hit component as a result, then check if it is an instanced static mesh and get it’s world-space transform to spawn the physics blueprint actor instead (replacing the instance at location). Use the remove instance node to despawn the rigged foliage and return it to an unrigged foliage.

An unoptimized way to check different foliage types and replace them with the correct blueprint actor is to use the hit result to get the name of the hit component and compare it to a string (the name of the foliage actor components). However, the names within the foliage actor components are impractical, always following “InstanceFoliageStaticMeshComponent_” followed by an index number corresponding to the order they are in the foliage painting tool (e.g., InstanceFoliageStaticMeshComponent_0 is the first).

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ea9f7415-ecb9-4b73-9785-61b2009450d1/FoliageInteraction_HitReturn.png

When a player moves away from foliage it needs to be replaced with the static meshes as interaction is no longer needed. Create a foliage manager for respawning static meshes. This is a performant method because each instance is a child of one component, thereby generating only one draw call. In the manager you may add hierarchical instanced static meshes for each type of foliage you have as well as contain functions to replace foliage that is called by each object interacting with the foliage. Each object keeps an array that checks the distance between foliage actors it spawns and itself - when the distance exceeds a specific amount of units, call the replacement method from the foliage manager to spawn an instance at the right transform.

Materials work can be added on top of the foliage manager to further enhance the interactivity of the foliage. Because distance fields do not calculate from skeletal meshes, you will need to add a static cylinder mesh (invisible) that distance fields may be calculated from.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/59757b77-6602-4124-99c7-8c04f65a2acb/FoliageInteraction_HitBox.png

Other Forces and Actors

Because the foliage that interacts with the player is a physics actor, adding additional forces and impulses is simple. An example would be a grenade that casts a sphere ray cast distance field on the hit location, switching every hit component, adding a radial impulse and replacing the actors again.