Get Assets by Class - how to find all BP assets of given class?

Based on @Chatouille and @VernamRD answer:

Here the version which only requires a UClass* Base Class

	static FORCEINLINE_DEBUGGABLE bool GetBlueprintsFromBaseClass(UClass* InBaseClass,
	                                                         TArray<FAssetData>& FoundAssets)
	{
		if (!IsValid(InBaseClass))
		{
			return false;
		}
		
		FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(
			"AssetRegistry");

		TMultiMap<FName, FString> TagsValues;

		// All native CDOs should be in memory - we can look up native subclasses of InNativeClass
		for (FThreadSafeObjectIterator It(InBaseClass); It; ++It)
		{
			const UClass* Class = It->GetClass();
			if (Class->IsNative() && Class->ClassDefaultObject == *It)
			{
				TagsValues.AddUnique(FBlueprintTags::NativeParentClassPath,
				                     FObjectPropertyBase::GetExportPath(Class));
			}
		}

		return AssetRegistryModule.Get().GetAssetsByTagValues(TagsValues, FoundAssets);
	}

Usage:

TArray<FAssetData> AssetData;
GetBlueprintsFromBaseClass(MyUInheritUObjectClass::StaticClass(), AssetData);
2 Likes