Save SkeletalMesh from USkeletalMergingLibrary::MergeMeshes to .uasset

Yaulp
Wed, 06 Mar 2024 19:43:44 +0000
Programming & Scripting

Hi everyone !
I want to save a SkeletalMesh made with MergeMeshes to .uasset.
I made this function that can save UObjects to .uasset :

UFUNCTION(BlueprintCallable)
static bool SaveToAsset(UObject* object, FString path, FString name)
{
	UE_LOG(LogTemp, Warning, TEXT("~~~~~~~~~~ Saving to asset... ~~~~~~~~~~"));
	if (object == NULL) {
		UE_LOG(LogTemp, Error, TEXT("Object is null."));
		return false;
	}
	// Find unique name and create package
	FString Name = name;
	for (int i = 1; FPackageName::DoesPackageExist(FString("/Game/" + path + Name)); i++)
		Name = name + FString::FromInt(i);
	UPackage* Package = CreatePackage(*FString("/Game/" + path + Name));
	UE_LOG(LogTemp, Warning, TEXT("Package created : %s"), *(Package->GetName()));

	// Duplicate object
	FObjectDuplicationParameters p(object, Package);
	p.DestName = FName(Name);
	UObject* DuplicatedObject = StaticDuplicateObjectEx(p);
	DuplicatedObject->SetFlags(RF_Public | RF_Standalone);

	// Save and return
	FString PackageFileName = FPackageName::LongPackageNameToFilename(Package->GetName(), FPackageName::GetAssetPackageExtension());
	bool bSucceeded = UPackage::SavePackage(Package, DuplicatedObject, DuplicatedObject->GetFlags(), *PackageFileName);
	if (bSucceeded) UE_LOG(LogTemp, Warning, TEXT("Saving Package succeded.")) else UE_LOG(LogTemp, Error, TEXT("ERROR : FAILED SAVING PACKAGE !"));
	return bSucceeded;
}

It works for the SkeletalMeshes I tried, and for most others UObjects.

But when I try to save the SkeletalMesh made with USkeletalMergingLibrary::MergeMeshes, if I click on the Content Drawer, Unreal crash.

Here is the end of the LOG :

[2024.03.06-18.54.51:269][482]LogTemp: Warning: ~~~~~~~~~~ Saving to asset... ~~~~~~~~~~
[2024.03.06-18.54.51:269][482]LogTemp: Warning: Package created : /Game/Assets/Humans/Metahuman/Preview/MergeMeshes_Saved
[2024.03.06-18.54.51:342][482]LogPackageLocalizationCache: Processed 64 localized package path(s) for 1 prioritized culture(s) in 0.012199 seconds
[2024.03.06-18.54.51:352][482]LogSavePackage: Moving output files for package: /Game/Assets/Humans/Metahuman/Preview/MergeMeshes_Saved
[2024.03.06-18.54.51:352][482]LogSavePackage: Moving '../../../../../../Users/Yaulp/Desktop/Unreal Projects/Game 5.3/Saved/MergeMeshes_Saved4454B5C74641DC680DA139880527D0F6.tmp' to '../../../../../../Users/Yaulp/Desktop/Unreal Projects/Game 5.3/Content/Assets/Humans/Metahuman/Preview/MergeMeshes_Saved.uasset'
[2024.03.06-18.54.51:353][482]LogTemp: Warning: Saving Package succeded.
[2024.03.06-18.54.51:355][482]LogViewport: Scene viewport resized to 1920x1006, mode Windowed.
[2024.03.06-18.54.51:369][482]PIE: Server logged in
[2024.03.06-18.54.51:370][482]PIE: Play in editor total start time 0,898 seconds.
[2024.03.06-18.54.51:410][482]LogViewport: Scene viewport resized to 1914x966, mode Windowed.
[2024.03.06-18.54.51:756][483]AssetCheck: New page: Asset Save: MergeMeshes_Saved
[2024.03.06-18.54.51:756][483]LogContentValidation: Display: Validating /Script/Engine.SkeletalMesh /Game/Assets/Humans/Metahuman/Preview/MergeMeshes_Saved.MergeMeshes_Saved
[2024.03.06-18.54.57:648][828]LogWorldSubsystemInput: UEnhancedInputDeveloperSettings::bEnableWorldSubsystem is false, the world subsystem will not be created!
[2024.03.06-18.54.57:656][828]LogOutputDevice: Warning:

Script Stack (0 frames) :

[2024.03.06-18.54.57:671][828]LogWindows: Error: appError called: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 771]
Array index out of bounds: 0 from an array of size 0

[2024.03.06-18.54.57:671][828]LogWindows: Windows GetLastError: L’opération a réussi. (0)
[2024.03.06-18.54.59:303][828]LogWindows: Error: === Critical error: ===
[2024.03.06-18.54.59:303][828]LogWindows: Error:
[2024.03.06-18.54.59:303][828]LogWindows: Error: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 771]
[2024.03.06-18.54.59:303][828]LogWindows: Error: Array index out of bounds: 0 from an array of size 0
[2024.03.06-18.54.59:303][828]LogWindows: Error:
[2024.03.06-18.54.59:303][828]LogWindows: Error:
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd5cfdbc7 UnrealEditor-Engine.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd49fa7b7 UnrealEditor-Engine.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd49df739 UnrealEditor-Engine.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd4a42a8c UnrealEditor-Engine.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd2dd0c43 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd2d971c6 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd295f19c UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd1be6c97 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd1c40fe1 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd1c70e45 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd22678ac UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd22647e7 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffcd2ebea06 UnrealEditor-UnrealEd.dll!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b068af2 UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b08d28c UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b08d37a UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b090854 UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b0a6984 UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ff70b0a9d7a UnrealEditor.exe!UnknownFunction []
[2024.03.06-18.54.59:303][828]LogWindows: Error: [Callstack] 0x00007ffd26377344 KERNEL32.DLL!UnknownFunction []

In addition, the asset has a size of 142 KB while just the body has a size of 17 MB :

I thought it was due to the missing LODs, so I tried this but it crashed too :

FLODUtilities::RegenerateLOD(Cast<USkeletalMesh>(DuplicatedObject), ITargetPlatform::GetPlatformFromOrdinal(25), 4, true, true);

Thanks in advance to anyone who will try to help me, if any. I tried to do everything I could.

3 posts - 3 participants