|
|
|
|
| #include "EditorValidator_Load.h"
|
|
|
| #include "AssetCompilingManager.h"
|
| #include "Engine/Engine.h"
|
| #include "Engine/World.h"
|
| #include "HAL/FileManager.h"
|
| #include "Kismet2/BlueprintEditorUtils.h"
|
| #include "Kismet2/KismetEditorUtilities.h"
|
| #include "Misc/PackageName.h"
|
| #include "Misc/Paths.h"
|
| #include "Validation/EditorValidator.h"
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(EditorValidator_Load)
|
|
|
| #define LOCTEXT_NAMESPACE "EditorValidator"
|
|
|
|
|
|
|
| TArray<FString> UEditorValidator_Load::InMemoryReloadLogIgnoreList = { TEXT("Enum name collision: '") };
|
|
|
| UEditorValidator_Load::UEditorValidator_Load()
|
| : Super()
|
| {
|
| }
|
|
|
| bool UEditorValidator_Load::IsEnabled() const
|
| {
|
|
|
| return !IsRunningCommandlet() && Super::IsEnabled();
|
| }
|
|
|
| bool UEditorValidator_Load::CanValidateAsset_Implementation(const FAssetData& InAssetData, UObject* InAsset, FDataValidationContext& InContext) const
|
| {
|
| return Super::CanValidateAsset_Implementation(InAsset) && InAsset != nullptr;
|
| }
|
|
|
| EDataValidationResult UEditorValidator_Load::ValidateLoadedAsset_Implementation(const FAssetData& InAssetData, UObject* InAsset, FDataValidationContext& Context)
|
| {
|
| check(InAsset);
|
|
|
| TArray<FString> WarningsAndErrors;
|
| if (GetLoadWarningsAndErrorsForPackage(InAsset->GetOutermost()->GetName(), WarningsAndErrors))
|
| {
|
| for (const FString& WarningOrError : WarningsAndErrors)
|
| {
|
| AssetFails(InAsset, FText::FromString(WarningOrError));
|
| }
|
| }
|
| else
|
| {
|
| AssetFails(InAsset, LOCTEXT("Load_FailedLoad", "Failed to get package load warnings and errors"));
|
| }
|
|
|
| if (GetValidationResult() != EDataValidationResult::Invalid)
|
| {
|
| AssetPasses(InAsset);
|
| }
|
|
|
| return GetValidationResult();
|
| }
|
|
|
| bool UEditorValidator_Load::GetLoadWarningsAndErrorsForPackage(const FString& PackageName, TArray<FString>& OutWarningsAndErrors)
|
| {
|
| check(!PackageName.IsEmpty());
|
| check(GEngine);
|
|
|
| UPackage* const ExistingPackage = FindPackage(nullptr, *PackageName);
|
|
|
| if (ExistingPackage == GetTransientPackage())
|
| {
|
| return true;
|
| }
|
|
|
|
|
| if (ExistingPackage && UWorld::IsWorldOrWorldExternalPackage(ExistingPackage))
|
| {
|
| return true;
|
| }
|
|
|
|
|
|
|
| if (ExistingPackage && !IsRunningCommandlet() && UEditorValidator::ShouldAllowFullValidation() && !ExistingPackage->ContainsMap() && !PackageName.EndsWith(TEXT("_BuiltData")))
|
| {
|
|
|
| const FString& SrcPackageName = PackageName;
|
| FString SrcFilename;
|
| const bool bSourceFileExists = FPackageName::DoesPackageExist(SrcPackageName, &SrcFilename);
|
| if (bSourceFileExists)
|
| {
|
| static int32 PackageIdentifier = 0;
|
| FString DestPackageName = FString::Printf(TEXT("/Temp/%s_%d"), *FPackageName::GetLongPackageAssetName(ExistingPackage->GetName()), PackageIdentifier++);
|
| FString DestFilename = FPackageName::LongPackageNameToFilename(DestPackageName, FPaths::GetExtension(SrcFilename, true));
|
| uint32 CopyResult = IFileManager::Get().Copy(*DestFilename, *SrcFilename);
|
| if (ensure(CopyResult == COPY_OK))
|
| {
|
|
|
| UPackage* LoadedPackage = nullptr;
|
| {
|
| FLyraValidationMessageGatherer::AddIgnorePatterns(InMemoryReloadLogIgnoreList);
|
| FLyraValidationMessageGatherer ScopedMessageGatherer;
|
|
|
| int32 LoadFlags = LOAD_ForDiff;
|
| {
|
| TArray<UObject*> AllExistingObjects;
|
| GetObjectsWithPackage(ExistingPackage, AllExistingObjects, false);
|
| TArray<UBlueprint*> AllNonDOBPs;
|
| for (UObject* Obj : AllExistingObjects)
|
| {
|
| UBlueprint* BP = Cast<UBlueprint>(Obj);
|
| if (BP && !FBlueprintEditorUtils::IsDataOnlyBlueprint(BP))
|
| {
|
| AllNonDOBPs.Add(BP);
|
| }
|
| }
|
| if (AllNonDOBPs.Num() > 0)
|
| {
|
| LoadFlags |= LOAD_DisableCompileOnLoad;
|
| for (UBlueprint* BP : AllNonDOBPs)
|
| {
|
| check(BP);
|
| FKismetEditorUtilities::CompileBlueprint(BP);
|
| }
|
| }
|
| }
|
| LoadedPackage = LoadPackage(NULL, *DestPackageName, LoadFlags);
|
|
|
|
|
|
|
| FAssetCompilingManager::Get().FinishAllCompilation();
|
|
|
| for (const FString& LoadWarningOrError : ScopedMessageGatherer.GetAllWarningsAndErrors())
|
| {
|
| FString SanitizedMessage = LoadWarningOrError.Replace(*DestFilename, *SrcFilename);
|
| SanitizedMessage = SanitizedMessage.Replace(*DestPackageName, *SrcPackageName);
|
| OutWarningsAndErrors.Add(SanitizedMessage);
|
| }
|
| FLyraValidationMessageGatherer::RemoveIgnorePatterns(InMemoryReloadLogIgnoreList);
|
| }
|
| if (LoadedPackage)
|
| {
|
| ResetLoaders(LoadedPackage);
|
| IFileManager::Get().Delete(*DestFilename);
|
| TArray<UObject*> AllLoadedObjects;
|
| GetObjectsWithPackage(LoadedPackage, AllLoadedObjects, true);
|
| for (UObject* Obj : AllLoadedObjects)
|
| {
|
| if (Obj->IsRooted())
|
| {
|
| continue;
|
| }
|
| Obj->ClearFlags(RF_Public | RF_Standalone);
|
| Obj->SetFlags(RF_Transient);
|
| if (UWorld* WorldToDestroy = Cast<UWorld>(Obj))
|
| {
|
| WorldToDestroy->DestroyWorld(true);
|
| }
|
| Obj->MarkAsGarbage();
|
| }
|
| GEngine->ForceGarbageCollection(true);
|
| }
|
| }
|
| else
|
| {
|
|
|
| return false;
|
| }
|
| }
|
| else
|
| {
|
|
|
| return false;
|
| }
|
| }
|
| else
|
| {
|
|
|
| FLyraValidationMessageGatherer ScopedMessageGatherer;
|
| LoadPackage(nullptr, *PackageName, LOAD_None);
|
| OutWarningsAndErrors = ScopedMessageGatherer.GetAllWarningsAndErrors();
|
| }
|
|
|
| return true;
|
| }
|
|
|
| #undef LOCTEXT_NAMESPACE
|
|
|
|
|