There are multiple parts to this question:
-
Using UE4Editor-Cmd.exe I need to automate the import for thousands of assets given file paths.
-
If I don’t do -replaceexisting it asks me every asset if I want to replace it.
-
JSON is no help either, “bReplaceExisting”:“false”, prompts every time also.
-
I’d like to use the new Scene Importing as Blueprints (FbxSceneImportFactory): HierarchyType = 2.
-
I’ve tried using FbxSceneImportFactory as the factory in the command line and it crashes.
-
I’ve tried using a C++ plugin that uses FbxSceneImportFactory, but I can’t get it to ignore the prompt and just make it. I’ve also tried FbxImportFactory, but it’s complicated and I feel like I’m leaving a lot out and making a big mess, and there is no HierarchyType access.
-
ImportSettings - “bImportScene”:1 doesn’t do it.
I have a C# tool that automates the creation of the JSON importsettings file. This is edited down to 4 files. It took me a while to figure out how to make different destinations because there is no documentation, so i hope this helps someone. You’ll notice “bReplaceExisting”:“false”, and it prompts for every import.
{"ImportGroups":[
{"FileNames":[
"Z:/Building/Exterior/GC_Rack/GC_Rack_1.fbx",
"Z:/Building/Exterior/HVAC_Ceiling_Unit/HVAC_Ceiling_Unit_1.fbx",
"Z:/Building/Exterior/Ice_Merchandiser_Leer_L40_Slant/Ice_Merchandiser_Leer_L40_Slant_1.fbx",
],
"bReplaceExisting":"false",
"DestinationPath":"/Game/Assets/Building/Exterior/",
"FactoryName":"FbxFactory",
"ImportSettings":{
"AnimSequenceImportData":{},"SkeletalMeshImportData":{},"TextureImportData":{},
"StaticMeshImportData":{"bCombineMeshes":1,"bAutoGenerateCollision":1,"bRemoveDegenerates":1}
}}
,
{"FileNames":[
"Z:/Building/Exterior/Signage_Fuel_Center/Food_Panels_1.fbx",
],
"bReplaceExisting":"false",
"DestinationPath":"/Game/Assets/Building/Exterior/Signage_Fuel_Center",
"FactoryName":"FbxFactory",
"ImportSettings":{
"AnimSequenceImportData":{},"SkeletalMeshImportData":{},"TextureImportData":{},
"StaticMeshImportData":{"bCombineMeshes":1,"bAutoGenerateCollision":1,"bRemoveDegenerates":1}
}}
]}
then it runs this:
"C:\Program Files\Epic Games\UE_4.21\Engine\Binaries\Win64\UE4Editor-Cmd.exe" "F:\UE4\v4_21_Projects\v4_21_Projects.uproject" -run=ImportAssets -importSettings="C:\UnrealImport\ImportSettings3.json" -AllowCommandletRendering -nosourcecontrol > "C:\UnrealImport\LOG.txt"
I don’t want it to replace so I did not use -replaceexisting
Here is as close as I have gotten with C++ — Warning, this is messy and bad
TArray Files;
Files.Add(TEXT("Z:/Signage_Fuel_Center/Sign.fbx"));
Files.Add(TEXT("Z:/AutoCareCenter/Water_Heater_Water_Heater_1.fbx"));
UFbxSceneImportFactory *FbxSceneFactory = nullptr;
for (UClass* Class : TObjectRange())
{
if (Class->IsChildOf<UFbxSceneImportFactory>())
{
UFbxSceneImportFactory* TestFactory = Class->GetDefaultObject<UFbxSceneImportFactory>();
if (TestFactory->FactoryCanImport(Files[0]))
{
/// Pick the first one for now
FbxSceneFactory = TestFactory;
break;
}
}
}
/*UFbxFactory *FbxFactory = nullptr;
for (UClass* Class : TObjectRange())
{
if (Class->IsChildOf<UFbxFactory>())
{
UFbxFactory* TestFactory = Class->GetDefaultObject<UFbxFactory>();
if (TestFactory->FactoryCanImport(Files[0]))
{
/// Pick the first one for now
FbxFactory = TestFactory;
break;
}
}
}*/
FString RootDestinationPath = "/Game/Assets/";
FString OutDir;
UClass* ImportAssetType = FbxSceneFactory->ResolveSupportedClass();
UnFbx::FFbxImporter* FbxImporter = UnFbx::FFbxImporter::GetInstance();
UnFbx::FBXImportOptions* GlobalImportSettings = FbxImporter->GetImportOptions();
UnFbx::FBXImportOptions::ResetOptions(GlobalImportSettings);
GlobalImportSettings->bImportScene = true;
for (int i = 0; i < Files.Num(); i++)
{
FString PathPart;
FString FilenamePart;
FString ExtensionPart;
FPaths::Split(Files[i], PathPart, FilenamePart, ExtensionPart);
OutDir = PathPart.Replace(TEXT("Z:/Projects/Asset_Library/Maya/"), *RootDestinationPath);
//
UAutomatedAssetImportData* newdata = NewObject<UAutomatedAssetImportData>();
newdata->bReplaceExisting = true;
newdata->DestinationPath = OutDir;
FbxSceneFactory->SetAutomatedAssetImportData(newdata);
bool bImportWasCancelled;
FString Name = ObjectTools::SanitizeObjectName(FPaths::GetBaseFilename(Files[i]));
FString PackageName = FPaths::Combine(*OutDir, *Name);
const FString QualifiedName = PackageName + TEXT(".") + Name;
UPackage* Pkg = CreatePackage(nullptr, *PackageName);
//
const TCHAR* Parms = TEXT("");
UObject* Result = FbxSceneFactory->ImportObject(ImportAssetType, Pkg, FName(*Name), RF_Public | RF_Standalone | RF_Transactional, Files[i], Parms, bImportWasCancelled);
UBlueprint *BP = Cast<UBlueprint>(Result);
FbxSceneFactory->SetAutomatedAssetImportData(nullptr);
}