Issues with multiple mesh sections referencing the same MaterialIndex and Nanite

Hi,

We’ve noticed that if you create a mesh with multiple sections which point to the same MaterialIndex but reference different areas of the mesh (for example to set bVisibleInRayTracing or bCastShadow seperately, but otherwise use the same material) this works for a non-Nanite mesh but for a Nanite mesh the sections seem to be merged together. Looking at the Nanite build code it seems to conflate the MaterialIndex and SectionIndex in some spots, for example the build code works with MaterialIndices but the rendering code uses SectionIndices which causes the mesh to render incorrectly if there isn’t a 1-1 mapping and they aren’t in the same order.

Is this a known issue or a something which is a limitation of Nanite itself?

Steps to Reproduce
Create a UStaticMesh with multiple FMeshSectionInfos which point to the same MaterialIndex but different regions on the mesh.

Hi,

thanks for reporting this. Would you be able to provide a minimal repro project? That would greatly help in investigating this issue further.

Thanks,

Sam

Hi,

thanks for the great repro scene. It allowed me to reproduce the issue and fully understand the incorrect behavior when converting to Nanite. I started investigating and it doesn’t look like this issue is known (a search on the public issue tracker did not come up with any similar issues), but I’ve found three other related cases that might be relevant:

[Content removed]

[Content removed]

[Content removed]

I will dig a bit further to see if this issue has been reported before, if not I will file a bug report and update this case with the link. Let me know if you have more questions or comments in the meantime.

Best regards,

Sam

Hi,

after some more investigation, this seems to be an unknown issue, so I have filed a bug report. I will post the link to the public issue tracker here when it becomes available so you can track its progress.

Thanks,

Sam

Hi again,

this is the link to the issue on the public issue tracker: Unreal Engine Issues and Bug Tracker (UE\-347699)

If you have further questions, please let me know.

Thanks again,

Sam

Sure, here’s a sample project. There is a BP which generates a UStaticMesh programmatically into the TestMesh asset, but it’s not required to run it since I also included the result.

This mesh has two sections (one for each cube) and two material slots. However, you can edit it in the static mesh editor and point both sections at the same material slot and remove the unused material slot. This works as expected in TestMesh_NonNanite and you can toggle, for example, shadow casting on a single section so that only one cube casts a shadow, but both use the same single material slot.

Enabling Nanite on this mesh (TestMesh_Nanite) collapses these slots even though they contain different settings and it doesn’t seem possible to create multiple sections with the same material slot name on a Nanite mesh, one is always removed when the mesh builds. This seems like a bug and not something which is inherent to Nanite since the Nanite rendering code works in sections which reference materials, not materials directly, the same as the non-Nanite mesh rendering path.