PCGGeometryScriptInterop - not extracting materials with AppendMeshesFromPoints when given empty Dynamic Mesh

I’ve tracked the issue down to a check in “PCGGeometryHelpers::RemapMaterials”, for some reason a check is being done to see if the “ToMaterials” array is not empty (on the first line), when this doesn’t seem necessary and in fact causes this issue of materials not working properly when appending to an empty dynamic mesh.

void RemapMaterials(UE::Geometry::FDynamicMesh3& InMesh, const TArray<UMaterialInterface*>& FromMaterials, TArray<TObjectPtr<UMaterialInterface>>& ToMaterials, const UE::Geometry::FMeshIndexMappings* OptionalMappings)
{
    if (FromMaterials.IsEmpty() || ToMaterials.IsEmpty() || !InMesh.HasAttributes() || !InMesh.Attributes()->HasMaterialID())
    {
       return;
    }
...

Stepping/looking through the code it seems like it should append the materials to the ToMaterials array, regardless of it being empty or not, so I think this check can just be removed? “On my machine” it seems to work fine like this, and it solves the issue I was having :slight_smile:

void RemapMaterials(UE::Geometry::FDynamicMesh3& InMesh, const TArray<UMaterialInterface*>& FromMaterials, TArray<TObjectPtr<UMaterialInterface>>& ToMaterials, const UE::Geometry::FMeshIndexMappings* OptionalMappings)
{
    if (FromMaterials.IsEmpty() || !InMesh.HasAttributes() || !InMesh.Attributes()->HasMaterialID())
    {
       return;
    }
...

Let me know if you’d like to know any more info or anything else! :slight_smile:

Steps to Reproduce
Steps:

  1. Make a new PCG graph
  2. Inside the graph make an “Create Empty Dynamic Mesh” node
  3. Make and connect to that an “Append Meshes from Points” node
  4. Provide the “Append Meshes from Points” node with points and a mesh (a point grid + any mesh with a not-default material will do, just so it’s more obvious since this is a material issue)
  5. Notice that the appended meshes don’t have the material they’re supposed to have, even with the “Extract Material” option on

If you switch the dynamic mesh input to a mesh that already has materials (ie, if you use “Static Mesh To Dynamic Mesh Element” and plug that in) it will work again as intended.

Hi Jeffrey, thanks for reaching out!

I’ll make a Jira on our end to fix it for 5.7. Thanks for the report!

Have a great day

Adrien

This is submitted and will be in 5.7 :slight_smile: