# Auto Importing FBX via Commandlet

**URL:** <https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719>\
**Category:** Pipeline & Plugins\
**Tags:** commandlet, unreal-engine, FBX, import, editor, question\
**Created:** [September 2, 2014, 9:40pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719 "2014-09-02T21:40:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 2, 2014, 9:40pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/1 "2014-09-02T21:40:18Z")

</div>

We are working on a commandlet that will check a folder for FBX and texture files and run an automated import on them.

When manually importing a file, the Editor appears to use the functionality in UFbxFactory. I’m wondering if this is what we will need to tap into for the automated import as well and how best to do that.

Before we spend a lot of time potentially heading in the wrong direction, I wanted to see if anyone could offer some guidance (examples would be amazing if you have them:)). Thanks for any help you can give!

---

<div class="post-metadata">

**Author:** ![Matt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matt](https://forums.unrealengine.com/u/Matt)\
**Post date:** [September 6, 2014, 12:45am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/2 "2014-09-06T00:45:46Z")

</div>

You can do this in a commandlet to import assets:

```
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked("AssetTools");
TArray<UObject*> ImportedObjects = AssetToolsModule.Get().ImportAssets(FileToImport, PackagePath, FactoryToUse);

```

FactoryToUse is optional. If you don’t specify one it will figure it out. However the major problem with FBX is that a dialog appears asking for FBX settings. FBX’s are complicated and we cant easily determine in all cases what is in the file and what the user wants without asking ( and there could be multiple things in the file). You are going to have to work around this. I suggest constructing your own UFbxFactory instance, passing it in to the method above and adding some method to the UFbxFactory to specify the settings up front and not show the dialog. There is some basic auto-detection of asset type in the FBX file so simply adding a flag to not show the dialog and use the defaults might work out OK for you.

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 6, 2014, 3:30am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/3 "2014-09-06T03:30:13Z")

</div>

I’m getting a compiler error, any ideas?

Error 1 error C2783: ‘TModuleInterface &FModuleManager::LoadModuleChecked(const FName)’ : could not deduce template argument for ‘TModuleInterface’ P:\Unreal Projects\SandboxrImport\Source\SandboxrImport\AutoImport.cpp 13 1 SandboxrImport

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 6, 2014, 3:59am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/4 "2014-09-06T03:59:38Z")

</div>

Think I got it…had to add a few things:

`
const FName moduleName = "AssetTools";
FModuleManager::LoadModuleChecked(moduleName);
`

`FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked(moduleName);
`

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 6, 2014, 5:50am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/5 "2014-09-06T05:50:39Z")

</div>

Currently getting an exception when trying to **ImportAssets()**…

`
TArray ImportedObjects = AssetToolsModule.Get().ImportAssets(files, importPath);
`

Giving me this:

`
First-chance exception at 0x000007FEDBABD231 (UE4Editor-Documentation.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000C68.
Unhandled exception at 0x000007FEDBABD231 (UE4Editor-Documentation.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000C68.
`

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 7, 2014, 3:54am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/6 "2014-09-07T03:54:25Z")

</div>

When I run the commandlet with this:

`
TArray files;
files.Add(TEXT("P:/Unreal Projects/SandboxrImport/Content/NeedImport/T_Worker_D_adj02.tga"));
FString packagePath = TEXT(“/Game/Textures/blah”);
`

`TArray ImportedObjects = AssetToolsModule.Get().ImportAssets(files, packagePath);
`

Which is throwing an exception:

`
[2014.09.08-00.49.57:846][0]LogWindows: Assertion failed: IsValid() [File:P:\Unreal Projects\UnrealEngine\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 647]
`

Changing the package path to “/Game/Textures” gives me this exception:

`
[2014.09.08-19.52.23:580][0]LogFactory: FactoryCreateBinary: Texture with TextureFactory (0 0 P:/Unreal Projects/SandboxrImport/Content/Textures/NeedImport/T_Worker_D_adj02.tga)
[2014.09.08-19.52.23:649][0]LogTexture:Display: Building textures: T_Worker_D_adj02 (AutoDXT)
'UE4Editor.exe' (Win32): Loaded 'P:\UNREAL~1\UnrealEngine\Engine\Binaries\Win64\UE4Editor-AssetRegistry.dll'. Symbols loaded.
[2014.09.08-19.52.27:465][0]LogAssetRegistry: FAssetRegistry took 0.0108 seconds to start up
'UE4Editor.exe' (Win32): Loaded 'P:\Unreal Projects\UnrealEngine\Engine\Binaries\Win64\UE4Editor-DirectoryWatcher.dll'. Symbols loaded.
First-chance exception at 0x000007FEE1C7FE3F (UE4Editor-UnrealEd.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000DB0.
Unhandled exception at 0x000007FEE1C7FE3F (UE4Editor-UnrealEd.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000DB0.
`

---

<div class="post-metadata">

**Author:** ![blurdot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@blurdot](https://forums.unrealengine.com/u/blurdot)\
**Post date:** [September 9, 2014, 2:12pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/7 "2014-09-09T14:12:58Z")

</div>

It looks like we can’t use ImportAssets from a commandline call to a commandlet. The Main() in the commandlet seems to fire before the Editor is fully loaded which is causing eexceptions from GEditor-\>Broadcast in AssetTools.cpp.

As an alternative, I was able to use FEditorDelegates::OnMapOpened in order to fire my import function automatically, which works since the map is not loaded until the Editor is fully loaded. This seems a bit hacky, but does the job.

I could not find a way to wait for the Editor to fully load with the commandlet. I don’t think this is intentional, so it might be a bug with commandlets running editor functions.

---

<div class="post-metadata">

**Author:** ![iceprincefounder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@iceprincefounder](https://forums.unrealengine.com/u/iceprincefounder)\
**Post date:** [March 25, 2016, 7:18am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/8 "2016-03-25T07:18:06Z")

</div>

Hi,blurdot :

I am trying to import FBX file to my project but I got some problem,it bother me for a long time.

```
TArray<UObject*> FileToImport; 
FileToImport.Add(TEXT("P:/UnrealProjects/SandboxrImport/Content/NeedImport/T_Worker_D_adj02.tga"));
TArray<UObject*> ImportedObjects = AssetToolsModule.Get().ImportAssets(FileToImport, PackagePath, FactoryToUse);

```

but it did not work,

Would you mind show me your .cpp file,this is my [e-mail:iceprincefounder@qq.com](mailto:e-mail:iceprincefounder@qq.com).

Very appreciate your help!

---

<div class="post-metadata">

**Author:** ![Muzaheed](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/muzaheed/32/778940_2.png) [@Muzaheed](https://forums.unrealengine.com/u/Muzaheed)\
**Post date:** [July 4, 2016, 11:14am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/9 "2016-07-04T11:14:44Z")

</div>

@blurdot, Were you able to use Commandlet for it?  
Or any other solution?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [November 14, 2016, 8:00pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/10 "2016-11-14T20:00:31Z")

</div>

It’s in the 4.14 prerelease and sorta buggy at the moment, but there is a new Commandlet coming to do this! It’s called ImportAssetCommandlet ([see commit](https://github.com/EpicGames/UnrealEngine/commit/4fa92bfa50a95733c735e2f92b76f5c9e36b0d4c)) and can be invoked as `UE4Editor.exe filepath.uproject -run=ImportAssets -source=filepath.fbx -dest=assetpath -importsettings=""`.

---

<div class="post-metadata">

**Author:** ![Matt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matt](https://forums.unrealengine.com/u/Matt)\
**Post date:** [November 14, 2016, 8:40pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/11 "2016-11-14T20:40:26Z")

</div>

Yeah its pretty new and has no documentation at all yet. If you find bugs with it please point them out.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [November 14, 2016, 9:21pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/12 "2016-11-14T21:21:58Z")

</div>

Well, it crashes if you don’t have source control enabled, since `PackageStates` is always empty:

```
[2016.11.14-19.33.56:799][0]LogWindows:Error: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\Containers/Array.h] [Line: 634] 
[2016.11.14-19.33.56:799][0]LogWindows:Error: Array index out of bounds: 0 from an array of size 0
...
[2016.11.14-19.33.56:799][0]LogWindows:Error: UE4Editor-UnrealEd.dll!UImportAssetsCommandlet::ImportAndSave() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\commandlets\importassetscommandlet.cpp:195]

```

---

<div class="post-metadata">

**Author:** ![Matt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Matt](https://forums.unrealengine.com/u/Matt)\
**Post date:** [November 15, 2016, 2:09pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/13 "2016-11-15T14:09:13Z")

</div>

That was fixed but it may not make it into a public release until 4.14.1

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [November 17, 2016, 10:47pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/14 "2016-11-17T22:47:48Z")

</div>

Thanks. It looks like it did indeed miss the cut ☹

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [November 19, 2016, 12:17am UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/15 "2016-11-19T00:17:08Z")

</div>

Another bug with ImportAssetsCommandlet.  
This commandlet can easily crash when trying to save engine and plugin content.  
For example, if somewhere in my `UFactory`, I call `LoadObject`, in the process of loading the Material, it calls `UObjectBaseUtility::MarkPackageDirty`. there is a safeguard in there to not set the dirty flag when loading objects _BUT_ the flag does get set in Commandlets.

This manifests as a crash when it tries to save the dirty assets:

```
[2016.11.19-00.13.11:170][0]LogInit:Display: SourceControl:Error: Error fatal: C:/Program Files (x86)/Epic Games/4.14/Engine/Content/EngineSky/M_Sky_Panning_Clouds2.uasset: 'C:/Program Files (x86)/Epic Games/4.14/Engine/Content/EngineSky/M_Sky_Panning_Clouds2.uasset' is outside repository

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2739cbe1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2739cbe1](https://forums.unrealengine.com/u/anonymous_user_2739cbe1)\
**Post date:** [December 28, 2016, 9:10pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/16 "2016-12-28T21:10:02Z")

</div>

The commandlet has a argument called “importsettings”. Does anyone know how this JSON file should look like? I couldn’t find any information.

---

<div class="post-metadata">

**Author:** ![IAmBug](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IAmBug](https://forums.unrealengine.com/u/IAmBug)\
**Post date:** [November 19, 2018, 2:06pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/18 "2018-11-19T14:06:40Z")

</div>

Matt, I want konw how to suppress import dialogs when import fbx scene？I will be very grateful for your answer.

---

<div class="post-metadata">

**Author:** ![Walmart3DTeam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Walmart3DTeam](https://forums.unrealengine.com/u/Walmart3DTeam)\
**Post date:** [December 3, 2018, 4:03pm UTC](https://forums.unrealengine.com/t/auto-importing-fbx-via-commandlet/292719/19 "2018-12-03T16:03:35Z")

</div>

I’ve tried a lot of different ways to get this to work and still nothing is perfect. I’ve got the commandlet solved but I’d like to make it a new “scene import”. Here’s a post with all of my code and maybe something will help you.  
[fbx-automated-command-line-import](https://answers.unrealengine.com/questions/851065/fbx-automated-command-line-import-ue4editor-cmdexe.html)
