Skeletal mesh imported from blender has too many materials.

I have a skeletal Mesh that uses only three materials and no sub meshes. I know the problem stems from how the mesh was made, I used pieces from mesh in another file with it’s own material and joined them to the mesh, assigning them the final material of course. Blender seems to retain this information as when it’s imported in the Unreal you can see clearly where the patches are.

Here is the mesh in blender with one of the patches selected. note that it’s using the exact same material as the surrounding area.

And this is an image from Unreal. as you can see It made the patch it’s own element and there far more then just 3 elements.

Making each patch it’s own mesh is pretty unacceptable and unreasonable. I tried using modifiers and all sorts of stuff to see if made new faces. But nothing seems to be working, And there doesn’t seem to be anyway to say combine Material Elements in Unreal which would be a favorable solution if possible.

Recently I’ve come across a solution that helps but is far from perfect and requires some trial and error without being destructive to the mesh in Blender, It require opening up the FBX File and editing the “LayerElementMaterial” Portion of the file. I notice in a mesh with only 3 materials in blender it had 4 unique material indexes because of the patching in the FBX file, For some reason blender remembers that there used to be a previous material on the face and exports it despite not existing in the blender file anymore. So you have to find out which indexes when combined make up the faces of the original material in blender

Example

Materials: 1,2,3,4,1,1,2…

Materials 1 and 2 are part of the same group in blenders so change all 2’s to 1’s or all 1’s to 2’s so the correct file might look like.

Materials: 1,1,3,4,1,1,1…

Without a doubt this is not a great solution but it’s better then trying to fix it in blender or working around the extra groups in UE4.

After trying to use my previous solution I realized that for large meshes this process was time consuming even with find and replace. So I decided to try my hand at writing a program that actually did the editing for me but this meant take a deeper look in to the FBX file format. So I started skimming through the FBX of a small mesh with the same problem. I noticed it had index for materials up to 10 despite the fact that that there were only 3 or so materials in blender and about 4 indexes used for the the mesh for example it was using materials 0, 3, 4, and 10. So where are all those extra materials coming from I thought to myself. Then finally I got to where the materials were defined and to my surprise it was making materials for not only materials applied to the mesh but textures in the blender file.

The textures were things like UV map layouts and some textures but ultimately stuff that was not even used by the mesh.

After clearing out the textures by Shift clicking the X on the texture in the UV editor and saving and reloading the file. I tried exporting and sure enough it stopped exporting the extra materials and assigning them incorrectly to the geometry.

To keep it simple.

  1. Shift click the X on extra and useless materials in the material panel to remove them from the file.
  2. Shift click the X on any textures you find in the UV editor to remove them from the file.
  3. Save and reload the file so all unused data is fully purged.
  4. Export and everything should be fine!

I hope that’s the end of it for now. There seemingly no answer to the problem out there that doesn’t involve edited the FBX file by hand. Hope this helps anyone in need.