Duplicated Mesh sockets when re-importing fbx for SkeletalMesh

Looking at the code in SkeletalMeshImportUtils::RestoreExistingSkelMeshData… it looks like we should just call empty on the array (SkeletalMesh->GetMeshOnlySocketList().Empty()) before calling this code

// Assign sockets from old version of this SkeletalMesh.
// Only copy ones for bones that exist in the new mesh.
for (int32 i = 0; i < MeshData->ExistingSockets.Num(); i++)
{
	const int32 BoneIndex = SkeletalMesh->GetRefSkeleton().FindBoneIndex(MeshData->ExistingSockets[i]->BoneName);
	if (BoneIndex != INDEX_NONE)
	{
		SkeletalMesh->GetMeshOnlySocketList().Add(MeshData->ExistingSockets[i]);
	}
}

I tested this and it works and it solves the bug. However, I was wondering if I am missing something.

I have put breakpoint in the code and it looks like this will save the existing socket array.

ExistSkelMeshDataPtr = SkeletalMeshImportUtils::SaveExistingSkelMeshData(ExistingSkelMesh, !ImportOptions->bImportMaterials, ImportSkeletalMeshArgs.LodIndex);

Later the call to SkeletalMeshImportUtils::RestoreExistingSkelMeshData will copy it back into the array… which does not make sense (unless we empty the array first).

We found few SkeletalMesh that had a lot of duplicates in the array… There was even one asset that had 1572861 items in the Socket array. I had to write a commandlet to clear the duplicates because the editor would freeze when trying to show sockets in the Skeletal Mesh editor.

Let me know if emptying the array is the right thing to do… I would like to avoid causing bigger problems. To be honest, I find it weird to find this kind of bug in 5.6, I think that SkeletalMeshImportUtils code dates from the UE4 era.

Thank you for your help.

[Attachment Removed]

Steps to Reproduce
Repro

  1. Open a skeletal mesh
  2. Create a socket
  3. Convert it to a mesh socket
  4. Save the asset
  5. Re-import the fbx for the asset
  6. Notice that the mesh socket is now duplicated

100% reproducible

[Attachment Removed]

Hey Stéphane.

Thanks for reporting this issue!

It seems like you narrowed down the origin of the problem : Without emptying the `SkeletalMesh->GetMeshOnlySocketList()` the mesh sockets will effectively double every reimport.

I would say it’s the right fix to do.

Keep in mind that this bug happens on the Legacy importer only.

As a workaround, you can switch to Interchange importer by using the Cmd `Interchange.FeatureFlags.Import.FBX True`.

Hope this helps

[Attachment Removed]

Thank you for your answer

It seems like someone deactivated this during the 5.6 integration. Apparently we have tools built the legacy importer.

Do you think it could be risky to continue using the legacy importer?

[Attachment Removed]

Hey Stéphane,

It dependents a lot on the nature of the tools you built and how much risk you are able to take.

Like most legacy framework, the Legacy importer is probably going to be more stable but very limited if you need more features and flexibility compared to Interchange. It will also have less support over time (and eventually be removed at some point).

If you want more details, you can look at the documentation page on how to customize Interchange and if this cover your needs : https://dev.epicgames.com/documentation/unreal\-engine/importing\-assets\-using\-interchange\-in\-unreal\-engine

[Attachment Removed]