FSkeletalMeshMerge is producing the desired combined mesh but the mesh doesn’t animate as intended
I’m using the following code:
.h
#pragma once
#include "CoreMinimal.h"
#include "Components/SkeletalMeshComponent.h"
#include "SkeletalMeshCombined.generated.h"
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYGAME_API USkeletalMeshCombined : public USkeletalMeshComponent
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
TArray<USkeletalMesh*> MeshesToCombine;
virtual void BeginPlay() override;
};
.cpp
#include "SkeletalMeshCombined.h"
#include "SkeletalMeshMerge.h"
void USkeletalMeshCombined::BeginPlay()
{
Super::BeginPlay();
if (GetOwner() == nullptr)
return;
if (MeshesToCombine.Num() > 0)
{
TArray<USkeletalMesh*> mergeMeshes;
mergeMeshes.Empty(MeshesToCombine.Num());
for (int32 i = 0; i < MeshesToCombine.Num(); i++)
{
if (MeshesToCombine[i] == nullptr)
continue;
mergeMeshes.Add(MeshesToCombine[i]);
}
if (mergeMeshes.Num() > 0)
{
USkeletalMesh* targetMesh = NewObject<USkeletalMesh>(this, FName("MergedMesh"), EObjectFlags::RF_NoFlags);
TArray<FSkelMeshMergeSectionMapping> sectionMappings;
FSkeletalMeshMerge merger(targetMesh, mergeMeshes, sectionMappings, 0);
const bool mergeStatus = merger.DoMerge();
check(mergeStatus == true);
//Set the skeleton for the combined mesh
targetMesh->Skeleton = mergeMeshes[0]->Skeleton;
//Use the new combined mesh
this->SetSkeletalMesh(targetMesh);
}
}
}
It produces this mesh:
But it looks like this when animating:
I might be using FSkeletalMeshMerge incorrectly but this seems like a bug.
Any ideas on what might be causing this?