Download

Getting Blueprint UClass at Runtime

This post is more a confirmation than it is a question.

I’ve been searching for the best way to get the UClass of a Blueprint at runtime and it seems the only way to do it is through the constructor using static ConstructorHelpers::FObjectFinder.

Is there a better way I’m not seeing?

YourBlueprintObject->GeneratedClass

will tell you the blueprint class of a UBlueprint object :slight_smile:

YourBlueprintObject->Class is for C++ level classes,


If you just want a quick way to include a BlueprintClass in your C++

you can make it a UPROPERTY() and set it from the Editor Default Properties on an already existing Blueprint, such as Character blueprint



```

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=BPClasses)
UClass* PotentialBP;

```



Rama

Late response but to get the Blueprint object I’d still have to use ConstructorHelpers::FObjectFinder yes? Which can only be used in the constructor if I’m not mistaken. Is there a more dynamic way of achieving this or is the only solution to hardcode any references I may need.

Hi,

it depends. What do you want to do with it? Are you searching for an already existing instance of the Class or do you want to create a new one?

If you are searching for an existing instance, you should already have it referenced somewhere, or in worst case can iterate through all the Actors in the Scene implementing your Baseclass.

If you want to create a new instance, i.e. for spawning a Mesh or Particle-System or stuff like that, you could use StaticLoadObject:



Cast<MyBlueprintClass>(StaticLoadObject(MyBlueprintClass::StaticClass(), NULL, *mypath));


see also the page in the wiki.

Cheers,
Indy