Merging Meshes and Materials using Commandlet

I am trying to import a datasmith file in headless mode, using a C++ commandlet. To handle the import and manage the assets I am using a Dataprep recipe which works fine when executed from the Editor, but not when executed from the commandlet.

This is how I execute the dataprep asset:

FString const AssetPath = Asset.ObjectPath.ToString();
UE_LOG(LogCommandletSample, Display, TEXT("Getting Dataprep Asset %s"), *AssetPath);

UObject* LoadedAsset = Asset.GetAsset();
UDataprepAsset* DataprepAsset = Cast<UDataprepAsset>(LoadedAsset);
UE_LOG(LogCommandletSample, Display, TEXT("Executing Dataprep Asset..."));
FDataprepCoreUtils::ExecuteDataprep(DataprepAsset, MakeShared<FDataprepCoreUtils::FDataprepLogger>(), MakeShared<FDataprepCoreUtils::FDataprepProgressUIReporter>());
  1. The import works fine when executed from the commandlet, however I am struggling to do somthing like “Save all” from the commandlet. I have tried to call FEditorFileUtils::SaveDirtyPackages() but that does not work.

  2. I want to merge the imported meshes, and their materials like this:


    Merging the meshes works, but when a MeshMergingSettings node is added (to merge the materials), the process crashes, this is what is says in the commandline:

[2022.01.18-16.45.59:227][  0]LogWindows: Error: === Critical error: ===
[2022.01.18-16.45.59:227][  0]LogWindows: Error:
[2022.01.18-16.45.59:228][  0]LogWindows: Error: Fatal error!
[2022.01.18-16.45.59:228][  0]LogWindows: Error:
[2022.01.18-16.45.59:229][  0]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000
[2022.01.18-16.45.59:229][  0]LogWindows: Error:
[2022.01.18-16.45.59:230][  0]LogWindows: Error: [Callstack] 0x00007ffe4bc91b6d UE4Editor-Engine.dll!UMaterialInterface::AnalyzeMaterialProperty() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Engine\Private\Materials\MaterialShared.cpp:3905]
[2022.01.18-16.45.59:230][  0]LogWindows: Error: [Callstack] 0x00007ffe15d9160b UE4Editor-MeshMergeUtilities.dll!FMeshMergeUtilities::DetermineMaterialVertexDataUsage() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Developer\MeshMergeUtilities\Private\MeshMergeUtilities.cpp:521]
[2022.01.18-16.45.59:231][  0]LogWindows: Error: [Callstack] 0x00007ffe15da3193 UE4Editor-MeshMergeUtilities.dll!FMeshMergeUtilities::MergeComponentsToStaticMesh() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Developer\MeshMergeUtilities\Private\MeshMergeUtilities.cpp:2091]
[2022.01.18-16.45.59:231][  0]LogWindows: Error: [Callstack] 0x00007ffe0f78e538 UE4Editor-EditorScriptingUtilities.dll!UEditorLevelLibrary::MergeStaticMeshActors() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Editor\EditorScriptingUtilities\Source\EditorScriptingUtilities\Private\EditorLevelLibrary.cpp:1398]
[2022.01.18-16.45.59:232][  0]LogWindows: Error: [Callstack] 0x00007ffe0f7a3bb9 UE4Editor-EditorScriptingUtilities.dll!UEditorLevelLibrary::execMergeStaticMeshActors() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Editor\EditorScriptingUtilities\Intermediate\Build\Win64\UE4Editor\Inc\EditorScriptingUtilities\EditorLevelLibrary.gen.cpp:419]
[2022.01.18-16.45.59:232][  0]LogWindows: Error: [Callstack] 0x00007ffe529fa465 UE4Editor-CoreUObject.dll!UObject::execCallMathFunction() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:956]
[2022.01.18-16.45.59:233][  0]LogWindows: Error: [Callstack] 0x00007ffe529fc7d8 UE4Editor-CoreUObject.dll!UObject::execLetBool() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:2797]
[2022.01.18-16.45.59:233][  0]LogWindows: Error: [Callstack] 0x00007ffe529d3bdd UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:1093]
[2022.01.18-16.45.59:234][  0]LogWindows: Error: [Callstack] 0x00007ffe529a26ba UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:924]
[2022.01.18-16.45.59:234][  0]LogWindows: Error: [Callstack] 0x00007ffe529d37e0 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:1154]
[2022.01.18-16.45.59:234][  0]LogWindows: Error: [Callstack] 0x00007ffe529d3bdd UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:1093]
[2022.01.18-16.45.59:235][  0]LogWindows: Error: [Callstack] 0x00007ffe529d3024 UE4Editor-CoreUObject.dll!UObject::ProcessInternal() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:1181]
[2022.01.18-16.45.59:235][  0]LogWindows: Error: [Callstack] 0x00007ffe526f1a44 UE4Editor-CoreUObject.dll!UFunction::Invoke() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp:5679]
[2022.01.18-16.45.59:236][  0]LogWindows: Error: [Callstack] 0x00007ffe529d2b43 UE4Editor-CoreUObject.dll!UObject::ProcessEvent() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp:2018]
[2022.01.18-16.45.59:236][  0]LogWindows: Error: [Callstack] 0x00007ffe1122f9ad UE4Editor-DataprepCore.dll!UDataprepOperation::OnExecution() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Intermediate\Build\Win64\UE4Editor\Inc\DataprepCore\DataprepOperation.gen.cpp:252]
[2022.01.18-16.45.59:237][  0]LogWindows: Error: [Callstack] 0x00007ffe111f8d05 UE4Editor-DataprepCore.dll!UDataprepOperation::ExecuteOperation() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Source\DataprepCore\Private\DataprepOperation.cpp:99]
[2022.01.18-16.45.59:237][  0]LogWindows: Error: [Callstack] 0x00007ffe111dce7a UE4Editor-DataprepCore.dll!<lambda_82aa7928d57b774ecd734d749b3ff160>::operator()() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Source\DataprepCore\Private\DataprepActionAsset.cpp:672]
[2022.01.18-16.45.59:237][  0]LogWindows: Error: [Callstack] 0x00007ffe111f69ea UE4Editor-DataprepCore.dll!UDataprepActionAsset::ExecuteAction() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Source\DataprepCore\Private\DataprepActionAsset.cpp:714]
[2022.01.18-16.45.59:238][  0]LogWindows: Error: [Callstack] 0x00007ffe111f92b7 UE4Editor-DataprepCore.dll!UDataprepAssetInterface::ExecuteRecipe_Internal() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Source\DataprepCore\Private\DataprepAssetInterface.cpp:191]
[2022.01.18-16.45.59:238][  0]LogWindows: Error: [Callstack] 0x00007ffe111f7a1c UE4Editor-DataprepCore.dll!FDataprepCoreUtils::ExecuteDataprep() [C:\Users\Nick\Documents\UnrealEngine\Engine\Plugins\Enterprise\DataprepEditor\Source\DataprepCore\Private\DataprepCoreUtils.cpp:307]
[2022.01.18-16.45.59:239][  0]LogWindows: Error: [Callstack] 0x00007ffe111a2b03 UE4Editor-KolloquiumVR.dll!UMyCommandlet::ExecuteAllDataprep() [C:\Users\Nick\Documents\UnrealEngine\Projects\KolloquiumVR\Source\KolloquiumVR\MyCommandlet.cpp:68]
[2022.01.18-16.45.59:239][  0]LogWindows: Error: [Callstack] 0x00007ffe111a2c8e UE4Editor-KolloquiumVR.dll!UMyCommandlet::Main() [C:\Users\Nick\Documents\UnrealEngine\Projects\KolloquiumVR\Source\KolloquiumVR\MyCommandlet.cpp:35]
[2022.01.18-16.45.59:239][  0]LogWindows: Error: [Callstack] 0x00007ff7918b9c7a UE4Editor-Cmd.exe!FEngineLoop::PreInitPostStartupScreen() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:3436]
[2022.01.18-16.45.59:240][  0]LogWindows: Error: [Callstack] 0x00007ff7918b0d5d UE4Editor-Cmd.exe!GuardedMain() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Launch\Private\Launch.cpp:132]
[2022.01.18-16.45.59:240][  0]LogWindows: Error: [Callstack] 0x00007ff7918b10ea UE4Editor-Cmd.exe!GuardedMainWrapper() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
[2022.01.18-16.45.59:241][  0]LogWindows: Error: [Callstack] 0x00007ff7918b410d UE4Editor-Cmd.exe!LaunchWindowsStartup() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:273]
[2022.01.18-16.45.59:241][  0]LogWindows: Error: [Callstack] 0x00007ff7918c54b4 UE4Editor-Cmd.exe!WinMain() [C:\Users\Nick\Documents\UnrealEngine\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:320]
[2022.01.18-16.45.59:241][  0]LogWindows: Error: [Callstack] 0x00007ff7918c73e2 UE4Editor-Cmd.exe!__scrt_common_main_seh() [d:\a01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
[2022.01.18-16.45.59:242][  0]LogWindows: Error: [Callstack] 0x00007ffededd7034 KERNEL32.DLL!UnknownFunction []
[2022.01.18-16.45.59:242][  0]LogWindows: Error: [Callstack] 0x00007ffee03c2651 ntdll.dll!UnknownFunction []

This does not happen in the Editor, so I think I am missing some important information about how commandlets work and what they are capable of. Unfortunately I cannot find much information about that. Why can part of the Dataprep recipe be executed from the commmandlet, but specifically merging the materials creates issues? I hope somebody know something about this, and thank you for your help!

Edit: As an alternative, I tried to do the same task with a Editor Utility Object, however I cannot even load the Editor Utility Object asset from the asset registry like I could the Dataprep asset. AssetRegistryModule.Get().GetAssetsByClass(EditorUtilityObjectBaseClassName, EditorUtilityObjectList, true) returns no assets, even though there is an Editor Utility Object in the project.

I solved all my problems by using a python commandlet instead (Scripting the Editor using Python | Unreal Engine Documentation). Specifically, the flag -ExecutePythonScript (and not -run=pythonscript) to run in the full editor and get all functionalities in a non-headless mode.

I had used C++ because I thought it would be convenient to have direct access to the source code, but it’s not worth it.