RealtimeStyleTransferRuntime/Source/LyraEditor/Validation/EditorValidator_MaterialFun...

120 lines
3.9 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "EditorValidator_MaterialFunctions.h"
2022-09-13 07:18:28 +00:00
#include "AssetRegistry/AssetData.h"
#include "AssetRegistry/IAssetRegistry.h"
#include "Containers/Set.h"
#include "Containers/UnrealString.h"
#include "HAL/Platform.h"
#include "Internationalization/Text.h"
#include "Logging/LogCategory.h"
#include "Logging/LogMacros.h"
#include "LyraEditor.h"
2022-05-23 18:41:30 +00:00
#include "Materials/Material.h"
2022-09-13 07:18:28 +00:00
#include "Materials/MaterialFunction.h"
#include "Misc/AssertionMacros.h"
#include "Misc/AssetRegistryInterface.h"
#include "Templates/Casts.h"
#include "Templates/UnrealTemplate.h"
#include "Trace/Detail/Channel.h"
#include "UObject/Class.h"
#include "UObject/NameTypes.h"
#include "UObject/Object.h"
#include "UObject/Package.h"
#include "UObject/TopLevelAssetPath.h"
#include "Validation/EditorValidator.h"
2022-05-23 18:41:30 +00:00
#include "Validation/EditorValidator_Load.h"
#define LOCTEXT_NAMESPACE "EditorValidator"
UEditorValidator_MaterialFunctions::UEditorValidator_MaterialFunctions()
: Super()
{
}
bool UEditorValidator_MaterialFunctions::CanValidateAsset_Implementation(UObject* InAsset) const
{
return Super::CanValidateAsset_Implementation(InAsset) && (InAsset ? InAsset->IsA(UMaterialFunction::StaticClass()) : false);
}
EDataValidationResult UEditorValidator_MaterialFunctions::ValidateLoadedAsset_Implementation(UObject* InAsset, TArray<FText>& ValidationErrors)
{
UMaterialFunction* MaterialFunction = Cast<UMaterialFunction>(InAsset);
check(MaterialFunction);
if (UEditorValidator::ShouldAllowFullValidation())
{
// Also load and check all directly referencing materials, as changes may have caused them to fail to compile
IAssetRegistry& AssetRegistry = IAssetRegistry::GetChecked();
TSet<FName> AllHardReferencers;
TArray<FName> PackagesToProcess;
PackagesToProcess.Add(MaterialFunction->GetOutermost()->GetFName());
do
{
TArray<FName> NextPackagesToProcess;
for (FName PackageToProcess : PackagesToProcess)
{
TArray<FName> HardReferencers;
AssetRegistry.GetReferencers(PackageToProcess, HardReferencers, UE::AssetRegistry::EDependencyCategory::Package, UE::AssetRegistry::EDependencyQuery::Hard);
for (FName HardReferencer : HardReferencers)
{
if (!AllHardReferencers.Contains(HardReferencer))
{
AllHardReferencers.Add(HardReferencer);
TArray<FAssetData> RefAssets;
AssetRegistry.GetAssetsByPackageName(HardReferencer, RefAssets, true);
for (const FAssetData& RefData : RefAssets)
{
if (RefData.IsRedirector())
{
NextPackagesToProcess.Add(RefData.PackageName);
break;
}
}
}
}
}
PackagesToProcess = MoveTemp(NextPackagesToProcess);
} while (PackagesToProcess.Num() > 0);
for (FName HardReferencer : AllHardReferencers)
{
FString HardReferencerStr = HardReferencer.ToString();
if (!IsInUncookedFolder(HardReferencerStr))
{
TArray<FAssetData> ReferencerAssets;
AssetRegistry.GetAssetsByPackageName(HardReferencer, ReferencerAssets, true);
for (const FAssetData& ReferencerAssetData : ReferencerAssets)
{
2022-08-23 15:30:42 +00:00
if (ReferencerAssetData.AssetClassPath == UMaterial::StaticClass()->GetClassPathName())
2022-05-23 18:41:30 +00:00
{
UE_LOG(LogLyraEditor, Display, TEXT(" Loading referencing material %s"), *HardReferencerStr);
TArray<FString> WarningsAndErrors;
if (UEditorValidator_Load::GetLoadWarningsAndErrorsForPackage(HardReferencerStr, WarningsAndErrors))
{
for (const FString& WarningOrError : WarningsAndErrors)
{
AssetFails(InAsset, FText::FromString(WarningOrError), ValidationErrors);
}
}
break;
}
}
}
}
}
if (GetValidationResult() != EDataValidationResult::Invalid)
{
AssetPasses(InAsset);
}
return GetValidationResult();
}
#undef LOCTEXT_NAMESPACE