How do I properly merge different skeletal meshes?

Hi, I’m trying to make a procedural crowd system and I want to be able to load different body parts from the content folder, choose randomly which pieces to use and then merge the skeletal meshes to have fewer draw calls and to better manage animations. I’m using this code to merge the meshes:

    USkeletalMesh* targetMesh = NewObject<USkeletalMesh>(this, FName("SkeletalMesh"), RF_Transient);
	TArray<FSkelMeshMergeSectionMapping> sectionMappings;
	FSkeletalMeshMerge merger(targetMesh, pieces, sectionMappings, 0);
	const bool mergeStatus = merger.DoMerge();
    check(mergeStatus == true);

	character->GetMesh()->SetSkeletalMesh(targetMesh, true);

It all went fine for a while as I was able to spawn multiple characters in the level without any problems. But at some point the editor started crashing giving me this message (I didn’t change the code when this started):

Assertion failed: SkeletalMeshLODInfo.Num() == SkeletalMeshRenderData->LODRenderData.Num() [File:D:\Build++UE4+Release-4.19+Compile\Sync\Engine\Source\Runtime\Engine\Private\SkeletalRender.cpp] [Line: 77] Mismatched LOD arrays. SkeletalMeshLODInfo.Num() = 1, SkeletalMeshRenderData->LODRenderData.Num() = -572662307

Before this started, I just created some blueprints to manage the spawning location of the characters, but these don’t affect anything mesh related of the characters, they just change the transforms’ location.
What’s more absurd to me is that I’m able to spawn one character correctly, then when I want to spawn the second, the editor crashes with that error.

What am I doing wrong?

This is the full exception message:

Assertion failed: SkeletalMeshLODInfo.Num() == SkeletalMeshRenderData->LODRenderData.Num() [File:D:\Build++UE4+Release-4.19+Compile\Sync\Engine\Source\Runtime\Engine\Private\SkeletalRender.cpp] [Line: 77] Mismatched LOD arrays. SkeletalMeshLODInfo.Num() = 1, SkeletalMeshRenderData->LODRenderData.Num() = -572662307

UE4Editor_Core!FDebug::AssertFailed() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:419]
UE4Editor_Engine!FSkeletalMeshObject::UpdateMinDesiredLODLevel() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\skeletalrender.cpp:80]
UE4Editor_Engine!FSkeletalMeshSceneProxy::GetMeshElementsConditionallySelectable() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\skeletalmesh.cpp:3217]
UE4Editor_Engine!FSkeletalMeshSceneProxy::GetDynamicMeshElements() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\skeletalmesh.cpp:3206]
UE4Editor_Renderer!FSceneRenderer::GatherDynamicMeshElements() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\renderer\private\scenevisibility.cpp:2110]
UE4Editor_Renderer!FSceneRenderer::ComputeViewVisibility() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\renderer\private\scenevisibility.cpp:2840]
UE4Editor_Renderer!FDeferredShadingSceneRenderer::InitViews() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\renderer\private\scenevisibility.cpp:3067]
UE4Editor_Renderer!FDeferredShadingSceneRenderer::Render() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\renderer\private\deferredshadingrenderer.cpp:593]
UE4Editor_Renderer!RenderViewFamily_RenderThread() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\renderer\private\scenerendering.cpp:2749]
UE4Editor_Renderer!TGraphTask

This is a really old post but I have the same problem… did you or anyone else find the solution please?..