So I have a code snippet guys, which converts a given skeletal Mesh to Procedural mesh at runtime, but I need a different functionality, I want it to only convert some bones, not the full skeletal mesh,
for example, if Input is given : upperarm_l, then it will show upperarm_l, lowerarm_l, and hand_l but not the other bones in procedural mesh,
here is the code that I have
void UGore::CopySkeletalMeshToProcedural(USkeletalMeshComponent* SkeletalMeshComponent, int32 LODIndex, FName InTargetBoneNaming)
{
if (!SkeletalMeshComponent || !ProcMeshComponent) return;
FSkeletalMeshRenderData* SkMeshRenderData = SkeletalMeshComponent->GetSkeletalMeshRenderData();
const FSkeletalMeshLODRenderData& DataArray = SkMeshRenderData->LODRenderData[LODIndex];
FSkinWeightVertexBuffer& SkinWeights = *SkeletalMeshComponent->GetSkinWeightBuffer(LODIndex);
TArray<FVector> VerticesArray;
TArray<FVector> Normals;
TArray<FVector2D> UV;
TArray<int32> Tris;
TArray<FColor> Colors;
TArray<FProcMeshTangent> Tangents;
int32 NumSourceVertices = DataArray.RenderSections[0].NumVertices;
for (int32 i = 0; i < NumSourceVertices; i++)
{
FVector SkinnedVectorPos = USkeletalMeshComponent::GetSkinnedVertexPosition(SkeletalMeshComponent, i, DataArray, SkinWeights);
VerticesArray.Add(SkinnedVectorPos);
FVector ZTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentZ(i);
FVector XTangentStatic = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.VertexTangentX(i);
Normals.Add(ZTangentStatic);
Tangents.Add(FProcMeshTangent(XTangentStatic, false));
FVector2D uvs = DataArray.StaticVertexBuffers.StaticMeshVertexBuffer.GetVertexUV(i, 0);
UV.Add(uvs);
Colors.Add(FColor(0, 0, 0, 255));
}
FMultiSizeIndexContainerData indicesData;
DataArray.MultiSizeIndexContainer.GetIndexBuffer(indicesData.Indices);
for (int32 i = 0; i < indicesData.Indices.Num(); i++)
{
uint32 a = indicesData.Indices[i];
Tris.Add(a);
}
// ✅ Create the procedural mesh
ProcMeshComponent->CreateMeshSection(0, VerticesArray, Tris, Normals, UV, Colors, Tangents, true);
ProcMeshComponent->SetWorldTransform(SkeletalMeshComponent->GetComponentTransform());
// ✅ Hide original skeletal mesh
AActor* Owner = GetOwner();
if (Owner)
{
USkeletalMeshComponent* Mesh = Owner->FindComponentByClass<USkeletalMeshComponent>();
if (Mesh)
{
Mesh->SetVisibility(false);
}
}
ProcMeshComponent->SetVisibility(true);
}
Thankyou for reading through