Skeletal Mesh Import from FBX does not respect materials set if there's no Material ID layer on the mesh

Some DCC packages do not export this layer if there’s only one FBX material assigned to the node and all the mesh polygons use that same material. Simple fix in FbxSkeletalMeshImport.cpp:

  	if (LayerElementMaterial)
		{
			switch(MaterialMappingMode)
			{
			// material index is stored in the IndexArray, not the DirectArray (which is irrelevant with 2009.1)
			case FbxLayerElement::eAllSame:
				{	
					Triangle.MatIndex = MaterialMapping[ LayerElementMaterial->GetIndexArray().GetAt(0) ];
				}
				break;
			case FbxLayerElement::eByPolygon:
				{	
					int32 Index = LayerElementMaterial->GetIndexArray().GetAt(LocalIndex);							
					if (!MaterialMapping.IsValidIndex(Index))
					{
						AddTokenizedErrorMessage(FTokenizedMessage::Create(EMessageSeverity::Warning, LOCTEXT("FbxSkeletaLMeshimport_MaterialIndexInconsistency", "Face material index inconsistency - forcing to 0")));
					}
					else
					{
						Triangle.MatIndex = MaterialMapping[Index];
					}
				}
				break;
			}
		}
		else //if we dont have a material id layer, assume all triangles use the first material
			Triangle.MatIndex = MaterialMapping[0];

The else branch at the end I added fixes the problem.

Also, both the times the _skinXX suffix is removed, the string manipulation is done WRONG.
In UnFbx::FFbxImporter::CreateUnrealMaterial
line

MaterialFullName = MaterialFullName.LeftChop(Offset+1);

should be

MaterialFullName = MaterialFullName.Left(Offset);

In UnFbx::FFbxImporter::SetMaterialSkinXXOrder
line

ImportData.Materials[MaterialIndex].MaterialImportName.LeftChop( Offset );

this line does NOTHING without an assignment operator, and also LeftChop should be just Left, like so

ImportData.Materials[MaterialIndex].MaterialImportName = ImportData.Materials[MaterialIndex].MaterialImportName.Left( Offset );

(if you didn’t actually want to remove the SkinXX suffix from the MaterialImportName, just remove this line and comment, as it is confusing)

Hi ,

I can send this information to our development team, but I would recommend submitting a pull request on GitHub to have your changes implemented into the Engine.

Send it, just saying what I needed to do to get my models imported properly.

We were trying to reproduce the original issue that you described, and have not had any success yet. Would you be able to provide the file for a model where this was happening for you and detail the steps you followed to export the model from your modeling software and import it into the Engine?