我尝试使用COmmandlet运行一份蓝图冒烟,以下是我的程序,当我有大量的蓝图需要冒烟编译时,他会在Commandlet退出时崩溃,这让我的自动化流程有一些困扰,TSharedPtr ArtCheckLibrary::CheckAllBluePirnt()
{
double LastGCTime = FPlatformTime::Seconds();
TArray<FAssetData> AssetDataList = GetAssetDataListByClass(UBlueprint::StaticClass(), "/Game");
for (const FAssetData& AssetData : AssetDataList)
{
FString const AssetPath = AssetData.ObjectPath.ToString();
UE_LOG(LogTemp, Display, TEXT("Loading and Compiling: '%s'..."), *AssetPath);
// Load with LOAD_NoWarn and LOAD_DisableCompileOnLoad as we are covering those explicitly with CompileBlueprint errors.
UBlueprint* LoadedBlueprint = Cast<UBlueprint>(StaticLoadObject(AssetData.GetClass(), /*Outer =*/nullptr, *AssetPath, nullptr, LOAD_NoWarn | LOAD_DisableCompileOnLoad));
if (LoadedBlueprint == nullptr)
{
UE_LOG(LogTemp, Error, TEXT("Failed to Load : '%s'."), *AssetPath);
continue;
}
else
{
LoadandComplier(LoadedBlueprint);
}
const double TimeNow = FPlatformTime::Seconds();
if (TimeNow - LastGCTime >= 10.0)
{
GEngine->TrimMemory();
LastGCTime = TimeNow;
}
}
TSharedPtr<FJsonObject> TemplateDataObject = MakeShareable(new FJsonObject);
if (NumWarnings1+ NumErrors1+ OtherErrors1 ==0)
{
return nullptr;
}
TemplateDataObject->SetNumberField(TEXT("Warning"), this->NumWarnings1);
TemplateDataObject->SetNumberField(TEXT("Error"), this->NumErrors1+this->OtherErrors1);
TemplateDataObject->SetStringField(TEXT("DataInfo"), this->ErrorMessages1);
return TemplateDataObject;
}
void ArtCheckLibrary::LoadandComplier(UBlueprint *BlueprintAsset)
{
FCompilerResultsLog MessageLog;
MessageLog.SetSourcePath(BlueprintAsset->GetPathName());
MessageLog.BeginEvent(TEXT("Compile"));
// EBlueprintCompileOptions::SkipGarbageCollection
FKismetEditorUtilities::CompileBlueprint(BlueprintAsset, EBlueprintCompileOptions::SkipSave, &MessageLog);
MessageLog.EndEvent();
if ((MessageLog.NumErrors + MessageLog.NumWarnings) > 0)
{
this->AssetsWithErrorsOrWarnings1.Add(BlueprintAsset->GetPathName());
this->NumErrors1 += MessageLog.NumErrors;
this->NumWarnings1 += MessageLog.NumWarnings;
}
for (TSharedRef<class FTokenizedMessage>& Message : MessageLog.Messages)
{
EMessageSeverity::Type Severity = Message->GetSeverity();
if (Severity == EMessageSeverity::Error || Severity == EMessageSeverity::Warning)
{
FString LogContent = "";
LogContent += "**" + BlueprintAsset->GetPathName() + "** :";
LogContent += *Message->ToText().ToString();
ErrorMessages1 += LogContent + TEXT("\n");
/* UE_LOG(LogTemp, Display, TEXT("%s"), *Message->ToText().ToString());*/
}
}
}