Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions Engine/Source/Runtime/AssetRegistry/Private/AssetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,14 @@ bool UAssetRegistryImpl::EnumerateAssets(const FARCompiledFilter& InFilter, TFun
return;
}

#if WITH_EDITOR
// Skip classes that report themselves as assets but that the editor AssetRegistry is currently not counting as assets
if (ShouldSkipAsset(Obj->GetClass()->GetFName(), InMemoryPackage->GetPackageFlags()))
{
return;
}
#endif

// Package name
const FName PackageName = InMemoryPackage->GetFName();

Expand Down Expand Up @@ -2117,9 +2125,17 @@ void UAssetRegistryImpl::AssetSearchDataGathered(const double TickStartTime, TBa
// Add the found assets
while (AssetResults.Num() > 0)
{
FAssetData*& BackgroundResult = AssetResults.Pop();
// Delete or take ownership of the BackgroundResult; it was originally new'd by an FPackageReader
TUniquePtr<FAssetData> BackgroundResult(AssetResults.Pop());
CA_ASSUME(BackgroundResult.Get() != nullptr);

CA_ASSUME(BackgroundResult);
#if WITH_EDITOR
// Skip Assets that we filter out
if (ShouldSkipAsset(BackgroundResult->AssetClass, BackgroundResult->PackageFlags))
{
continue;
}
#endif

// Try to update any asset data that may already exist
FAssetData* AssetData = State.CachedAssetsByObjectPath.FindRef(BackgroundResult->ObjectPath);
Expand All @@ -2128,20 +2144,16 @@ void UAssetRegistryImpl::AssetSearchDataGathered(const double TickStartTime, TBa
if (AssetData)
{
// If this ensure fires then we've somehow processed the same result more than once, and that should never happen
if (ensure(AssetData != BackgroundResult))
if (ensure(AssetData != BackgroundResult.Get()))
{
// The asset exists in the cache, update it
UpdateAssetData(AssetData, *BackgroundResult);

// Delete the result that was originally created by an FPackageReader
delete BackgroundResult;
BackgroundResult = nullptr;
}
}
else
{
// The asset isn't in the cache yet, add it and notify subscribers
AddAssetData(BackgroundResult);
AddAssetData(BackgroundResult.Release());
}

// Populate the path tree
Expand Down Expand Up @@ -2661,8 +2673,29 @@ void UAssetRegistryImpl::OnDirectoryChanged(const TArray<FFileChangeData>& FileC
ScanModifiedAssetFiles(ModifiedFiles);
}

bool UAssetRegistryImpl::ShouldSkipAsset(FName AssetClass, uint32 PackageFlags) const
{
// We do not yet support having UBlueprintGeneratedClasses be assets when the UBlueprint is also
// an asset; the content browser does not handle the multiple assets correctly and displays this
// class asset as if it is in a separate package. Revisit when we have removed the UBlueprint as an asset
// or when we support multiple assets.
static FName NAME_BlueprintGeneratedClass = TEXT("BlueprintGeneratedClass");
bool bIsCooked = (PackageFlags & PKG_FilterEditorOnly) != 0;
if (!bIsCooked && AssetClass == NAME_BlueprintGeneratedClass)
{
return true;
}
return false;
}

void UAssetRegistryImpl::OnAssetLoaded(UObject *AssetLoaded)
{
UPackage* Package = AssetLoaded->GetPackage();
if (Package && ShouldSkipAsset(AssetLoaded->GetClass()->GetFName(), Package->GetPackageFlags()))
{
return;
}

LoadedAssetsToProcess.Add(AssetLoaded);
}

Expand Down
3 changes: 3 additions & 0 deletions Engine/Source/Runtime/AssetRegistry/Private/AssetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ class UAssetRegistryImpl : public UObject, public IAssetRegistry
/** Called when a file in a content directory changes on disk */
void OnDirectoryChanged(const TArray<struct FFileChangeData>& Files);

/** Called to check whether we should filter out assets of the given class and packageflags from the editor's AssetRegistry */
bool ShouldSkipAsset(FName AssetClass, uint32 PackageFlags) const;

/** Called when an asset is loaded, it will possibly update the cache */
void OnAssetLoaded(UObject *AssetLoaded);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1492,11 +1492,18 @@ void FAssetRegistryState::AddAssetData(FAssetData* AssetData)
{
NumAssets++;

FAssetData*& ExistingByObjectPath = CachedAssetsByObjectPath.FindOrAdd(AssetData->ObjectPath);
if (ExistingByObjectPath)
{
UE_LOG(LogAssetRegistry, Error, TEXT("AddAssetData called with ObjectPath %s which already exists. ")
TEXT("This will overwrite and leak the existing AssetData."), *AssetData->ObjectPath.ToString());
}
ExistingByObjectPath = AssetData;

TArray<FAssetData*>& PackageAssets = CachedAssetsByPackageName.FindOrAdd(AssetData->PackageName);
TArray<FAssetData*>& PathAssets = CachedAssetsByPath.FindOrAdd(AssetData->PackagePath);
TArray<FAssetData*>& ClassAssets = CachedAssetsByClass.FindOrAdd(AssetData->AssetClass);

CachedAssetsByObjectPath.Add(AssetData->ObjectPath, AssetData);
PackageAssets.Add(AssetData);
PathAssets.Add(AssetData);
ClassAssets.Add(AssetData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ class ENGINE_API UBlueprintGeneratedClass : public UClass
#if WITH_EDITOR
virtual UClass* RegenerateClass(UClass* ClassToRegenerate, UObject* PreviousCDO) override;
#endif //WITH_EDITOR
virtual bool IsAsset() const override;

// End UObject interface

// UClass interface
Expand Down
13 changes: 12 additions & 1 deletion Engine/Source/Runtime/Engine/Private/BlueprintGeneratedClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ void UBlueprintGeneratedClass::PostLoad()
FPrimaryAssetId UBlueprintGeneratedClass::GetPrimaryAssetId() const
{
FPrimaryAssetId AssetId;
if (!ensure(ClassDefaultObject))
if (!ClassDefaultObject)
{
// All UBlueprintGeneratedClass objects should have a pointer to their generated ClassDefaultObject, except for the
// CDO itself of the UBlueprintGeneratedClass class.
verify(HasAnyFlags(RF_ClassDefaultObject));
return AssetId;
}

Expand Down Expand Up @@ -1583,6 +1586,14 @@ UClass* UBlueprintGeneratedClass::RegenerateClass(UClass* ClassToRegenerate, UOb
}
#endif

bool UBlueprintGeneratedClass::IsAsset() const
{
// UClass::IsAsset returns false; override that to return true for BlueprintGeneratedClasses,
// but only if the instance satisfies the regular definition of an asset (RF_Public, not transient, etc)
// and only if it is the active BPGC matching the Blueprint
return UObject::IsAsset() && !HasAnyClassFlags(CLASS_NewerVersionExists);
}

void UBlueprintGeneratedClass::Link(FArchive& Ar, bool bRelinkExistingProperties)
{
Super::Link(Ar, bRelinkExistingProperties);
Expand Down
Loading