Creating a SkeletalMesh saved asset from procedural mesh

We are trying to create a skeletal mesh asset saved from a customized avatar. We take the body parts and combine them to a single mesh using the FSkeletalMeshMerge functions. The merge works fine but then we want to save it as an asset so we can cache the results. We use this code and it does create an asset but it does not contain the skeletal mesh. It is like wrapper with a reference or something.

Here is what we are using:



void UAsMeshMergeLib::SaveMesh(USkeletalMesh* MeshToSave)
{
const FString PackageName = "/Game/SavedMesh";

UPackage* Package = CreatePackage(nullptr, *PackageName);
Package->FullyLoad();

const ERenameFlags Flags = REN_ForceNoResetLoaders | REN_DoNotDirty | REN_DontCreateRedirectors | REN_NonTransactional | REN_SkipGeneratedClasses;
FString newName = "GenSkelMesh";
MeshToSave->Rename(*newName, Package, Flags);
MeshToSave->AddToRoot();

Package->MarkPackageDirty();
FAssetRegistryModule::AssetCreated(MeshToSave);

const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());

UPackage::SavePackage(Package, MeshToSave, RF_Public | RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
}


Ideas?