DistanceFieldReplacementMesh doesn't work for Nanite meshes

We’d like to use the Distance Field Replacement Mesh feature for our Nanite meshes. We can’t, because the distance field result is clearly incorrect.

This seems to have been a problem for some years, as witnessed by this unresolved forum thread about the same issue: https://forums.unrealengine.com/t/distance-field-replacing-mesh-not-working-with-nanite-enabled/554518

Steps to Reproduce

  1. In Unreal Editor, open a static mesh asset.
  2. Make sure it’s Nanite enabled.
  3. Add another mesh as its Distance Field Replacement Mesh.
  4. Visualize distance fields to observe that the result is not the replacement mesh (but more like an intersection of the original mesh and the replacement mesh’s bounding box).
  5. Disable nanite in the original mesh.
  6. Observe that now the replacement mesh works correctly for the distance field.

Hello,

This issue is still unresolved and can be tracked here Unreal Engine Issues and Bug Tracker (UE\-186839)

The following fix was originally submitted but had to be backed out because it caused an issue due to missing dependency between the base mesh and the replacement mesh when async mesh compilation is used.

CL#26157686 Fix two issues with DistanceFieldReplacementMesh- if base mesh was Nanite, DistanceFieldReplacementMesh wouldn’t be used at all

- when DistanceFieldReplacementMesh was used, BuildSectionData was incorrect since it was setup using the base mesh which might use sections with different materials/sections.

If you are not using async mesh compilation you may be able to restore the CL, or use it as a base for understanding the general area where the fix should go.