Getting blueprint assets with the asset registry in packaged builds?

I need to get the UClass and the CDO of every blueprint in a specific folder that is derived from a class UMyClass.
In order to do this, I’m using the asset registry to load all UBlueprints in the folder.
Here is a simplified version of the code I’m using:

const FAssetRegistryModule& assetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
assetRegistryModule.Get().SearchAllAssets(true);
 
FARFilter filter;
filter.PackagePaths.Add(FName("/Game/GameContent/MyFolder"));
filter.bRecursivePaths = true;
filter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
 
TArray<FAssetData> bpAssets;
assetRegistryModule.Get().GetAssets(filter, bpAssets);
 
for (const auto& bpAsset : bpAssets)
{
	const UBlueprint* blueprint = Cast<UBlueprint>(bpAsset.GetAsset());
	TSubclassOf<UMyClass> bpClass = TSubclassOf<UMyClass>{blueprint->GeneratedClass};
	const UMyClass* bpCDO = bpClass->GetDefaultObject<UMyClass>();
	// Do stuff with the class and the CDO
}

This works fine in the editor, but fails in packaged builds (apparently the bpAssets array does get populated, but the cast to UBlueprint* inside the for loop seems to fail).
From what I understand, UBlueprints are replaced with UBlueprintGeneratedClasses in packaged builds, so I’m assuming this is the issue? I’m not sure how to rewrite this code to make it work both in the editor and in packaged builds, though (adding UBlueprintGeneratedClass::StaticClass()->GetClassPathName() to the filter’s class paths and casting to UBlueprintGeneratedClass* in the loop did not seem to solve the problem).
Any help would be appreciated. Thanks in advance!