Importing a fbx file in c++, but can't get it's dependencies on the first import.

Hello,

As the title says, I’m writing a plugin which has a button( inside SCompoundWidget class ) that OnClicked() imports a fbx file into UE4 content browser and saves it. It works fine, except one small annoying issue ( which haunts me for a week already :slight_smile: ), when I click that button once, it imports the skeletal mesh along with material, skeleton and physics asset and saves the skeletal mesh asset, but fails to get/log out the dependencies of the skeletal mesh( which are obviously the material, the skeleton and the physics asset ). However, when I click the same button the second time, it reimports the fbx file and guess what, it gets all of the dependencies just fine, as shown in the screenshot and code below. My best guess is, I’m missing something which should force-update / refresh the dependencies of the imported asset.

Could someone please help me with this or at least point me in the right direction? Or maybe there’s some other better way to get the dependencies?

Thanks in advance,
ArNavArt

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_193961_1591174270359_407”,“title”:“FBXDepIssue.jpg”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64



FReply SImportFBX_Mdl1_CompWidget::OnFBXFileImportClicked()
{
     FBXFileImportImpl();

     return FReply::Handled();
}

// Import FBX from specified path functions
void SImportFBX_Mdl1_CompWidget::FBXFileImportImpl()
{
     bool bIsCancelled = false;
     bool bShowFBXOptionsDialog = false;
     FString FBXFilePath = TEXT("C:/Users/arnav/Desktop/FBXFile/TorusSkeletal.fbx");
     FString FBXFileImportDestFolder = TEXT("/Game/ArNavFBX");

     UFbxFactory* TmpFactory = NewObject< UFbxFactory >(UFbxFactory::StaticClass(), FName("Factory"));
     UAssetImportTask* TmpImportTask = NewObject< UAssetImportTask >(UAssetImportTask::StaticClass());

     TmpFactory->AddToRoot();
     TmpFactory->ImportUI->MeshTypeToImport = FBXIT_SkeletalMesh;
     TmpFactory->ImportUI->StaticMeshImportData->bCombineMeshes = true;
     TmpFactory->ImportUI->SkeletalMeshImportData->bImportAsScene = true;
     TmpFactory->ImportUI->SkeletalMeshImportData->bConvertScene = true;
     TmpFactory->ImportUI->SkeletalMeshImportData->ImportRotation = FRotator( 0.f, 0.f, 0.f );

     if( bShowFBXOptionsDialog )
     {
          TmpFactory->EnableShowOption(); // Call to bring up Import Dialog window
     }

     TmpImportTask->bReplaceExisting = true;
     TmpImportTask->Factory = TmpFactory;
     TmpImportTask->bAutomated = (!bShowFBXOptionsDialog); // If true avoid Import Dialog window
     TmpImportTask->bSave = true;
     TmpImportTask->Options = TmpFactory->ImportUI;

     TmpFactory->SetAssetImportTask(TmpImportTask);

     FString TmpFBXFileName = ObjectTools::SanitizeObjectName( FPaths::GetBaseFilename( FBXFilePath ) );

     FString TmpPackageNm = FPaths::Combine(*FBXFileImportDestFolder, *TmpFBXFileName);
     UPackage* TmpAssetPackage = CreatePackage(NULL, *TmpPackageNm);
     TmpAssetPackage->FullyLoad();

     EObjectFlags TmpObjFlags = RF_Public | RF_Standalone | RF_Transactional;
     UObject* TmpImportedFBXObject = TmpFactory->ImportObject(TmpFactory->ResolveSupportedClass(), TmpAssetPackage, *TmpFBXFileName, TmpObjFlags, FBXFilePath, nullptr, bIsCancelled );

     TmpAssetPackage->MarkPackageDirty();

     TmpFactory->SetAssetImportTask(nullptr);
     TmpFactory->CleanUp();
     TmpFactory->RemoveFromRoot();


     if (TmpImportedFBXObject)//(TmpImportedFBXObject)
     {
          TArray< UPackage* > TmpPackagesArray;
          TmpPackagesArray.AddUnique(TmpImportedFBXObject->GetOutermost());

          TArray< UObject* > TmpFBXObjsArray;
          TmpFBXObjsArray.AddUnique(TmpImportedFBXObject);

          // Refresh content browser
          FContentBrowserModule& TmpContentBrowserMdl = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
          TmpContentBrowserMdl.Get().SyncBrowserToAssets(TmpFBXObjsArray, true);

          TmpAssetPackage->FullyLoad();
          TmpAssetPackage->SetDirtyFlag(true);
          TmpAssetPackage->MarkPackageDirty();

          FAssetRegistryModule& TmpAssetRegMdl = FModuleManager::GetModuleChecked< FAssetRegistryModule >("AssetRegistry");
          TmpAssetRegMdl.AssetCreated(TmpImportedFBXObject);

          GEditor->BroadcastObjectReimported(TmpImportedFBXObject);

          if (bSaveImportedFBX)
          {
              UEditorLoadingAndSavingUtils::SavePackages(TmpPackagesArray, false);
          }

          TArray< FName > TmpDepAssetNames;
          bool bHasDeps = TmpAssetRegMdl.Get().GetDependencies(TmpAssetPackage->GetFName(), TmpDepAssetNames, EAssetRegistryDependencyType::All);

          if (bHasDeps)
          {
               UE_LOG(LogArNavPlugin, Warning, TEXT("DEPENDENCY IS true: SSSSSSS"));
               for (FName& Fn : TmpDepAssetNames)
               {
                    UE_LOG(LogArNavPlugin, Warning, TEXT("DEPENDENCY Names: %s TTTTTT"), *Fn.ToString());
               }
          }
          else
          {
               UE_LOG(LogArNavPlugin, Warning, TEXT("DEPENDENY NOT FOUND TTTTTT"));
          }
     }
     else
     {
          UE_LOG(LogArNavPlugin, Warning, TEXT("NO IMPORT( I guess )"));
     }
}