How do I get a list of all blueprint classes, that are a child of a specific blueprint at runtime?

How do I get a list of all blueprint classes, that are a child of a specific blueprint, at runtime?

For example:
Say, I have a Blueprint called: “Parent”
Parent has 3 child blueprints, called “ChildA”, “ChildB”, and “ChildC”

Is there a way to add those three child classes to a class array dynamically at runtime?

Get All Actors of Class should do what you want. You set the parent BP class and it gives you an array of all the blueprints based on it.

That returns actors of the class that are already spawned.
I want an array of classes that can be spawned.

Basically, I want it to return a list of the blueprint classes that Ive added to the content browser.

Now I’m confused since your first post says at runtime and that node does exactly that?

:X Why don’t you add them before runtime? Just make a Class Array and add these 3 per hand.

I don’t think you can get classes of nonused BPs. :confused:

I know I can add them manually before runtime.
I wanted to set it up so I could make new classes at a later date, without having to constantly update the list manually.

Ah, ok. My mistake.

The node is looking for the wrong thing. I want classes not spawned actors.

I have been looking for a way to do this as well and unable to find a solution, but have found a decent compromise:

If you add an array of the Parent type to a Blueprint (say, your Controller), you can go into the Defaults tab of that Blueprint and fill the array manually there using the dropdowns. It’s faster and cleaner than doing it with Event Graph nodes.

did u find any solution of it?
through blueprint or c++ ?

same there)
think we need new node “get child classes”

It would be useful to have such functionality.
In UMG when creating list of items able to pick up or buildings to build - now I need to make data tables or arrays, which on the long run can be messy and unreliable.
Getting one array of classes derived from one particular class would solve quick feeding scroll list, combo boxes etc.

This is a old post but here is a solution using UObjectLibrary. Loading asset can take times.
UObjectLibrary* MyObjectLibrary = UObjectLibrary::CreateLibrary(AMyActor::StaticClass(), true, true);

MyObjectLibrary ->LoadBlueprintAssetDataFromPath(TEXT("/Game/PATH"));
MyObjectLibrary ->LoadAssetsFromAssetData();

TArray assetDataList;
MyObjectLibrary ->GetAssetDataList(assetDataList);

for (FAssetData& assetData : assetDataList)
{
if (UBlueprint* blueprintObject = Cast(assetData.GetAsset()))
{
if (UBlueprintGeneratedClass* blueprintGeneratedClass = Cast(blueprintObject->GeneratedClass.Get()))
{
const AMyActor* actorDC = Cast(blueprintGeneratedClass->ClassDefaultObject);
UClass* objClass = AMyActor->GetClass();
}
}
}

Sorry for the formating

1 Like

I’ve spent hour searching for a solution for this.

In short, you can get all the blueprint classes with this code:

	TArray<FAssetData> BlueprintAssets;
	FARFilter Filter;
	Filter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
	Filter.bRecursiveClasses = true;
	Filter.bRecursivePaths = true;
	AssetRegistry.GetAssets(Filter, BlueprintAssets);

All you have to do is to find your class in the list and build the “generated class” (i.e. the class that represents your blueprint):

for (FAssetData const& BlueprintAsset : BlueprintAssets)
{
    const FAssetTagValueRef GeneratedClassTag = BlueprintAsset.TagsAndValues.FindTag(FName("GeneratedClass"));
    if (GeneratedClassTag.IsSet())
    {
        FTopLevelAssetPath ClassPath(GeneratedClassTag.GetValue());
        if (DerivedClassNames.Contains(ClassPath))
        {
            // Now we can retrieve the class 
            FStringBuilderBase Builder;
            Builder << BlueprintAsset.PackageName << '.' << BlueprintAsset.AssetName << "_C";
        }
}

More information here: How to Browse All Blueprint Assets of a Defined Type in Unreal Engine – Flo GameDev blog

3 Likes

In addition to the answers posted above, I recently found this way to do it:

TArray<FString> FileNames;
IFileManager::Get().FindFiles(FileNames, *SearchDirectory);

It sets the FileNames TArray to a list of strings of the names of all the files found in SearchDirectory. I then prune the extension from the file names, and use this during game startup:

FString FullPathString = GameDirectory + "/" + PrunedFileName;
ConstructorHelpers::FClassFinder<AActor> StartupBPClass(*FullPathString);
if (StartupBPClass.Class != NULL)
	FoundClass = StartupBPClass.Class;

And add the FoundClass to a TArray that I store for later use.