Import Alembic with AbcImportSettings in Unreal 4.22 using python

Hello !
I do a script for import a Alembic animation in unreal engine with python but the parameter unreal.AssetImportTask.options for “Import options specific to the type of asset” does not work with AbcImportSettings :confused: I need use unreal.AbcImportSettings for import the asset like a skeletal mesh.

code:

import unreal
task = unreal.AssetImportTask()
task.filename = r'D:\Projet perso\Small Project\BlenderScriptWork\BlenderforUnrealEngineAddon\MyBlenderFiles\ExportedFbx\Alembic\Armature\SK_Armature.abc'
task.destination_path = r'/Game/Temp'
task.automated = True
task.set_editor_property('options', unreal.AbcImportSettings())
task.get_editor_property('options').set_editor_property('import_type', unreal.AlembicImportType.SKELETAL)
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
asset = unreal.find_asset(task.imported_object_paths[0])

I think it’s a bug
but I prefer to ask before if I did something wrong
Thank you for your reply !

I don’t have a ABC sketetal mesh to test, but i am wondering if this works?



...
task.automated = True
task.options= unreal.AbcImportSettings()
task.options.import_type = unreal.AlembicImportType.SKELETAL
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
...


I am testing abc import via python as well. In my case I can import abc as skeletal mesh using code like this:

import unreal

def import_alembic(abc_path, asset_path, asset_name):

# Create an import task.
import_task = unreal.AssetImportTask()

# Set base properties on the task.
import_task.filename = abc_path
import_task.destination_path = asset_path
import_task.destination_name = asset_name
import_task.automated = True # Suppress UI.
import_task.options = _get_alembic_import_options(frame_start = 1001, frame_end = 1090)

asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
asset_tools.import_asset_tasks([import_task])
imported_asset = import_task.get_editor_property('imported_object_paths')

if not imported_asset:
    unreal.log_warning('No assets were imported.')

def _get_alembic_import_options(frame_start = -1, frame_end = -1):

options = unreal.AbcImportSettings()
options.import_type = unreal.AlembicImportType.SKELETAL

options.sampling_settings.frame_start = frame_start
options.sampling_settings.frame_end = frame_end

# Debug output.
print(options.compression_settings)
print(options.conversion_settings)
print(options.geometry_cache_settings)
print(options.material_settings)
print(options.normal_generation_settings)
print(options.sampling_settings)
print(options.static_mesh_settings)

return options

However, options.sampling_settings.frame_start doesn’t work. The abc importer ignores the setting and always import my abc from frame 0, which is different from using the editor’s Alembic importer’s UI.

After a few hours of engine code debugging, I think it may be a bug of AssetTools module and AlembicImporter plugin.
My quick fix is, in AlembicImportFactory.cpp line 85:

UObject* UAlembicImportFactory::FactoryCreateFile(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, const FString& Filename, const TCHAR* Parms, FFeedbackContext* Warn, bool& bOutOperationCanceled)

......
......
if (!GIsRunningUnattendedScript && bShowOption)
{
    TSharedPtr<SAlembicImportOptions> Options;
    ShowImportOptionsWindow(Options, UFactory::CurrentFilename, Importer);
    // Set whether or not the user canceled
    bOutOperationCanceled = !Options->ShouldImport();
}
else
{
    const UAbcImportSettings* InImportSettings = (const UAbcImportSettings*)Parms;
    ImportSettings->CompressionSettings = InImportSettings->CompressionSettings;
    ImportSettings->ConversionSettings = InImportSettings->ConversionSettings;
    ImportSettings->GeometryCacheSettings = InImportSettings->GeometryCacheSettings;
    ImportSettings->ImportType = InImportSettings->ImportType;
    ImportSettings->SamplingSettings = InImportSettings->SamplingSettings;
    ImportSettings->bReimport = InImportSettings->bReimport;
    ImportSettings->MaterialSettings = InImportSettings->MaterialSettings;
    ImportSettings->NormalGenerationSettings = InImportSettings->NormalGenerationSettings;
    ImportSettings->StaticMeshSettings = InImportSettings->StaticMeshSettings;
}
......
......

in AssetTools.cpp line 2027:
UObject* Result = Factory->ImportObject(ImportAssetType, Pkg, FName(Name), RF_Public | RF_Standalone | RF_Transactional, Filename, (const TCHAR)Params.AssetImportTask->Options, bImportWasCancelled);

The idea is to pass through the task payload to the alembic importer. For now this works for me, not sure if these are the correct places to play around with.

Hello, Thank you for your answers ! I just saw them sorry, Finally I do my code with 20Tab python integration I’ll look for the next time

thanks for the info!