Can I delete some useless bone node in unreal?

I have a skeletal mesh with skeleton bone and controller which is created in 3DS Max.
I want to delete the controller in unreal after some calculation since these controllers do actually not effect vertices in skeletal mesh. However, I try to duplicate a skeleton from a skeletal mesh and modify its ReferenceSkeleton. But its failed because some reason.

Here is my test code:


auto Assets = UEditorUtilityLibrary::GetSelectedAssets();
	if (Assets.Num() == 0)
	{
		return;
	}
	USkeletalMesh* SkeletalMesh = Cast<USkeletalMesh>(Assets[0]);
	if (SkeletalMesh == nullptr)
	{
		return;
	}
	
	UAvatarBoneHierarchy* AvatarBoneHierarchy = AvatarDataManager::GetAvatarBoneHierarchy(PhysicId, ModelId);
	if (AvatarBoneHierarchy != nullptr)
	{
		AvatarBoneHierarchy->DivideIntoRealBoneAndControllerBone();
		USkeleton* RealBoneSkeleton = AvatarUtils::CreateACloneSkeleton("/Game/Avatar/RealBone", "RealBone", SkeletalMesh->GetSkeleton());
		USkeleton* ControlBoneSkeleton = AvatarUtils::CreateACloneSkeleton("/Game/Avatar/ControlBone", "ControlBone", SkeletalMesh->GetSkeleton());

		if (RealBoneSkeleton != nullptr)
		{
			FReferenceSkeleton& FRefSkeleton = RealBoneSkeleton->GetReferenceSkeleton();
			FRefSkeleton.Empty();
			FReferenceSkeletonModifier ReferenceSkeletonModifier(FRefSkeleton, RealBoneSkeleton);
			for (int32 i = 0; i < AvatarBoneHierarchy->RealBoneHierarchy->RefBoneInfos.Num(); ++i)
			{
				ReferenceSkeletonModifier.Add(AvatarBoneHierarchy->RealBoneHierarchy->RefBoneInfos[i], AvatarBoneHierarchy->RealBoneHierarchy->RefBoneTransforms[i]);
			}
			RealBoneSkeleton->MarkPackageDirty();
			FAssetRegistryModule::AssetCreated(RealBoneSkeleton);
		}

		if (ControlBoneSkeleton != nullptr)
		{
			FReferenceSkeleton& FRefSkeleton = ControlBoneSkeleton->GetReferenceSkeleton();
			FRefSkeleton.Empty();
			FReferenceSkeletonModifier ReferenceSkeletonModifier(FRefSkeleton, ControlBoneSkeleton);
			for (int32 i = 0; i < AvatarBoneHierarchy->ControlBoneHierarychy->RefBoneInfos.Num(); ++i)
			{
				ReferenceSkeletonModifier.Add(AvatarBoneHierarchy->ControlBoneHierarychy->RefBoneInfos[i], AvatarBoneHierarchy->ControlBoneHierarychy->RefBoneTransforms[i]);
			}
			ControlBoneSkeleton->MarkPackageDirty();
			FAssetRegistryModule::AssetCreated(ControlBoneSkeleton);
		}
	}

I could create “RealBoneSkeleton” and “ControlBoneSkeleton” successfully.
But when I tried to attach it to the original Skeletal Mesh, failures or crashes always happene.

Is there any way to achieve my goal?