Download

Using ParallelFor to multithread import uasset

I use the ParallelFor to increase speed to convert local file to unreal assests,so in ParallelFor lambda function i use the UPackage to create package,but when i import the file it came the error
[Assertion failed: IsInGameThread() [File:D:/UnrealEngine-4.26.2-release/Engine/Source/Runtime/RenderCore/Private/RenderingThread.cpp] [Line: 1335] ]
The import code List here:

ParallelFor(FileNameMapNum, [&](int32 id) {
UPackage* Package = CreatePackage(NULL, AssetPath);
Package->FullyLoad();
UVolumeTexture
volumeTexture= NewObject(Package, *TextureName, RF_Public | RF_Standalone | RF_MarkAsRootSet);
//Then i fill the volumeTexture to the new create volume Texture object
Package->MarkPackageDirty();
FAssetRegistryModule::AssetCreated(volumeTexture);
FString PackageFileName = FPackageName::LongPackageNameToFilename(AssetPath, FPackageName::GetAssetPackageExtension());
bool bSaved = UPackage::SavePackage(Package, volumeTexture, EObjectFlags::RF_Public | EObjectFlags::RF_Standalone, *PackageFileName, GError, nullptr, true, true, SAVE_NoError);
}, EParallelForFlags::BackgroundPriority);

Can someone tell me UPackage can or not use in the ParallelFor?

Well, you’re definitely causing some code that is protected with the IsInGameThread() check to run. Since that check is being hit, it will blow up. You’ll probably want to run the engine in Debugger so you can see the call stack, and find out what piece of your code is triggering that to happen, and then maybe you can figure out some way around it …