Download

How does ConstructorHelpers::FClassFinder work?

Hi there,

in my current project I need a way to in C++ either

a) find all classes inheriting from a certain C++ base class (including all Blueprint-generated classes) or
b) find a class by its name (again, including Blueprint-generatec classes)

I’ve tried a lot of things but couldn’t get anything to work in a standalone game (some things worked in the editor, but not in the game). Then today I came across this:

https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/ConstructorHelpers/FClassFinder/index.html

My problem is that I just have no idea how FClassFinder works and it’s impossible to find any kind of useful information about it on the internet. I’ve tried a few things myself, but so far I only got assertion fails. Can anyone give a usage example on this function? As in: what is the template parameter I have to pass in (I assume this is my C++ base-class?) and what kind of string do I have to pass in? And does this support both C++ and Blueprint-classes?

I’m on Unreal Engine 4.1.1, by the way. Don’t know if this is important, but it seems that the function’s implementation has changed since then.

Thanks in advance

You can iterate over all actors in the world and do a cast to your specific class:

That won’t work in my case because there aren’t any actors of the classes I’m searching for in the world at all.

Currently (AFAIK it was completely changed since 4.1.1) it works this way.

A code from ShooterGame sample:


static ConstructorHelpers::FClassFinder<APawn> BotPawnOb(TEXT("/Game/Blueprints/Pawns/BotPawn"));
BotPawnClass = BotPawnOb.Class;

where BotPawnClass is:


TSubclassOf<class APawn> BotPawnClass;

Notice, that the given path, does not include the exact class object (that would be “/Game/Blueprints/Pawns/BotPawn_C”), but only the blueprint asset.

1 Like

Thanks, that actually seems quite helpful! By now I’ve solved my problem in another (less elegant) way, using FObjectFinder to load the UBlueprint I needed, but this should come in handy if I switch to another UE version in the future.

Another question, though: Is there a way to get a blueprint’s path at runtime? Assuming I had:


static ConstructorHelpers::FClassFinder<APawn> BotPawnOb(TEXT("/Game/Blueprints/Pawns/BotPawn"));
UBlueprintGeneratedClass* BotPawnClass = Cast<UBlueprintGeneratedClass>(BotPawnOb.Class);
UBlueprint* BotPawnBlueprint = Cast<UBlueprint>(BotPawnClass->ClassGeneratedBy);

Now I can easily get my blueprint’s name by doing


BotPawnBlueprint->GetName()->ToString();

which would return “BotPawn” in this case. But is there away to actually get the full path to my blueprint ("/Game/Blueprints/Pawns/BotPawn" in this case) from either BotPawnClass or BotPawnBlueprint?

And another question: What would I do, if I also wanted to find C++ classes with FClassFinder? How would I do that? Do I just pass in the class name? I can’t possibly pass in a “path” to my C++ path, or can I?