SpeedTree wind resets when adding instances to HISM Component at runtime

I encountered an issue where the SpeedTree wind shader on a mesh was resetting after adding a new instance to a HierarchicalInstancedStaticMeshComponent.

When adding an instance to a HISM component at runtime, the render state for the component is destroyed and recreated. However, the FSpeedTreeWindComputation is deleted when the render state is destroyed and created again when the render state is created. This causes the instance to return to its original position creating a stuttering like effect.

Some notes about my testing:

  • I’m building the cluster tree of the HISM on a seperate thread using the BuildTreeAnyThread function
  • I have also tested this behavior in a simple Third Person project with a HISM component added to a Blueprint Actor with a function that adds an instance every time the user press a key.

I’m not sure whether this is behavior is desired but for anyone else having this issue the workaround is to add a second HISM component with an instance set to 0 scale. You can also just add the static mesh directly to the level instead (again, with scale set to 0).

This will ensure the FSpeedTreeWindComputation has at least one reference which will prevent it from being deleted when adding instances to the main HISM component.