I wrote a simple plugin to demonstrate the problem.
void MyWidget::Construct(const FArguments& InArgs)
{
this->ChildSlot
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
SNew(SButton).OnClicked(this, &MyWidget::OnBtnClicked)
]
+ SVerticalBox::Slot()
[
SNew(SButton).OnClicked(this, &MyWidget::OnBtnClickedDirect)
]
];
}
FReply MyWidget::OnBtnClicked()
{
AsyncTask(ENamedThreads::GameThread, []() { ImportAsset(); });
return FReply::Handled();
}
FReply MyWidget::OnBtnClickedDirect()
{
ImportAsset();
return FReply::Handled();
}
void MyWidget::ImportAsset()
{
TArray<FString> importPaths;
importPaths.Emplace("path_to_pictures_to_import");
UAutomatedAssetImportData* ImportDataAuto = NewObject<UAutomatedAssetImportData>();
ImportDataAuto->Filenames = importPaths;
ImportDataAuto->bSkipReadOnly = false;
ImportDataAuto->bReplaceExisting = true;
ImportDataAuto->DestinationPath = "/Game/Test/Textures";
IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
AssetTools.ImportAssetsAutomated(ImportDataAuto);
}
I create two buttons, one call the ImportAsset function directly, it’s ok. Another one call ImportAsset in AsyncTask, which will cause a crash.
Call ImportAssetsAutomated function to load images in AsyncTask seems to crash the editor. But use the same code to load fbx files is ok.
I found the problem in UE version 5.1 and above, 5.0 is ok.
I don’t know why, does anyone konw it? Thanks~