Fix for dragging a texture on a cube when a material already exists, and some protection against redirects in similar cases.

#rb matt.peters
#rb jason.stasik
#preflight 6351a5d9f92c325024c634e5

[CL 22669030 by Dan Thompson in ue5-main branch]
This commit is contained in:
Dan Thompson
2022-10-20 16:14:02 -04:00
parent d2496092f1
commit 7b15828416
2 changed files with 9 additions and 3 deletions

View File

@@ -571,8 +571,7 @@ UObject* FLevelEditorViewportClient::GetOrCreateMaterialFromTexture(UTexture* Un
const FString MaterialFullName = bCreateMaterialInstance ? (TEXT("MI_") + TextureShortName) : (TextureShortName + TEXT("_Mat"));
FString NewPackageName = FPaths::Combine(NewPackageFolder, MaterialFullName);
NewPackageName = UPackageTools::SanitizePackageName(NewPackageName);
UPackage* Package = CreatePackage(*NewPackageName);
NewPackageName = UPackageTools::SanitizePackageName(NewPackageName);
// See if the material asset already exists with the expected name, if it does, just return
// an instance of it.
@@ -580,7 +579,8 @@ UObject* FLevelEditorViewportClient::GetOrCreateMaterialFromTexture(UTexture* Un
if (AssetRegistry.GetAssetsByPackageName(*NewPackageName, OutAssetData) && (OutAssetData.Num() > 0))
{
UObject* FoundAsset = OutAssetData[0].GetAsset();
if (FoundAsset->IsA(UMaterialInterface::StaticClass()))
if (FoundAsset != nullptr && // Due to redirects we might have an asset by this name that actually doesn't exist under that name anymore.
FoundAsset->IsA(UMaterialInterface::StaticClass()))
{
return FoundAsset;
}
@@ -588,6 +588,8 @@ UObject* FLevelEditorViewportClient::GetOrCreateMaterialFromTexture(UTexture* Un
return nullptr;
}
UPackage* Package = CreatePackage(*NewPackageName);
// Variations for Base Maps.
TArray<FString> BaseSuffixes;
BaseSuffixes.Add("_D");