Last active
July 25, 2023 20:28
-
-
Save redxdev/30b29ab35fd43426ef1774b06e917377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); | |
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get(); | |
// Optional | |
TArray<FString> ContentPaths; | |
ContentPaths.Add(TEXT("/Game/My/Folder")); | |
AssetRegistry.ScanPathsSynchronous(ContentPaths); | |
// End Optional | |
TSet<FName> DerivedNames; | |
{ | |
TArray<FName> BaseNames; | |
BaseNames.Add(UMyBaseClass::StaticClass()->GetFName()); | |
TSet<FName> Excluded; | |
AssetRegistry.GetDerivedClassNames(BaseNames, Excluded, DerivedNames); | |
} | |
FARFilter Filter; | |
Filter.PackagePaths.Add(TEXT("/Game/My/Folder")); // optional | |
Filter.ClassPaths.Add(FTopLevelAssetPath(UBlueprint::StaticClass())); | |
Filter.bRecursiveClasses = true; | |
Filter.bRecursivePaths = true; | |
TArray<FAssetData> AssetList; | |
AssetRegistry.GetAssets(Filter, AssetList); | |
TArray<TSoftClassPtr<UMyBaseClass>> FoundClasses; | |
for (const FAssetData& Asset : AssetList) | |
{ | |
auto GeneratedClassPath = Asset.TagsAndValues.FindTag(TEXT("GeneratedClass")); | |
if (GeneratedClassPath.IsSet()) | |
{ | |
const FString ClassObjectPath = FPackageName::ExportTextPathToObjectPath(GeneratedClassPath.GetValue()); | |
const FString ClassName = FPackageName::ObjectPathToObjectName(ClassObjectPath); | |
if (!DerivedNames.Contains(*ClassName)) | |
{ | |
continue; | |
} | |
FoundClasses.Add(TSoftClassPtr<UMyBaseClass>(FSoftObjectPath(ClassObjectPath))); | |
} | |
} | |
// FoundClasses now has a list of *soft* class pointers. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment