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!
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.
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.
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) and can be invoked as UE4Editor.exe filepath.uproject -run=ImportAssets -source=filepath.fbx -dest=assetpath -importsettings="".
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:
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