C++ GetAllClasses extending from

Is there a method to get all classes that extend from a particular class?

Not Actors in the level, but classes. Such as all the blueprints made that extend from a common base class.

ConstructorHelpers::FClassFinder BaseResource(TEXT(“/Game/Blueprints/BaseClassBP”));

BaseResource.Class gets the class of BaseClassBP which is a Blueprint that extends ABaseClass, but, I have to name it specifically. Can this work on a Folder, or simply get all Blueprints that extend from that BaseClass instead?

For find all form same class you can use this

for( TObjectIterator<YourClass> It ; It ; ++It )
 {
 }

For finding all blueprint from a folder that a bit complicated

FAssetRegistryModule* AssetRegistryModule = &FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));

	TArray<FAssetData> AssetData;
	FARFilter Filter;
	Filter.ClassNames.Add(UBlueprint::StaticClass()->GetFName());
	Filter.PackagePaths.Add("/Game/YourFolder");
	AssetRegistryModule->Get().GetAssets(Filter, AssetData);

	for (TArray<FAssetData>::TConstIterator PkgIter = AssetData.CreateConstIterator(); PkgIter; ++PkgIter)
	{
		FAssetData Asset = *PkgIter;
		UBlueprint* BlueAsset = Cast<UBlueprint>(Asset.GetAsset());
		if (BlueAsset->ParentClass == YourClass::StaticClass()){
			//Do something
		}
	}

NOTE: for Packaging you need to include your folder to always cooked, if not it’s won’t find the assets.
Other way is you can make a ObjectLibrary blueprint, add whatever you need to that, then just get all blueprint from that.

Is there way to scan and registry in BP?

There a lot simpler way to do so, all objects in reflection system are standard UObjects, all of them deriveds from UField:

Classes are UClass… which i think you already know, but as you it;s just tip of a iceberg of reflection system :slight_smile:

Engine on start maps it self (from UHT generated code) spawning huge set of UObjects for each element of code, so engine can see it self and it’s code structure (hance the name “reflection”), including UClass objects for all classes. This ofcorse includes Blueprints as they contribute to entire engine code structure, as blueprint extending C++ classes. Because of that you can find all classes with TObjectIterator by searching via UClass. Problem is there no way to filter UClasses from itiration you will need to go thru all UClasses and this takes around 1 secound (from my own expirance), so i personally copy method that engine it self uses, create my own list (array) of classes once (on game start for example) and then used that short list of classes without any performance issues, here is code how to make such list:

in .h in some more global class

TArray<UClass*> Classes

in cpp:

for(TObjectIterator<UClass> It; It; ++It)
{
	if(It->IsChildOf(UHereYouTypeBaseClassYouWantToSearch::StaticClass()) 
	{
		Classes.Add(*It);
	}
}

You can add more conditions for adding class to the list for example !It->HasAnyClassFlags(CLASS_Abstract) if you want to skip useless for spawning abstract classes