How to cast to Blueprint class from C++?

I searched for a long time on many resources, but did not find a way to get the type of Blueprint class in the c++ class. I’m looking for a way to get the class type,not create an object. Just need to create containers of the same type as the blueprint class. How can I do this? Maybe I should connect some kind of library in the include? Thanks.

Uhhh, ok, I will create a c++ class, inherit the bluprint class from him, and then upcast it to my c++ class. But it seems like it’s not quite right, it’s a crutch

C++ is the foundation for Blueprint not the other way around so yes if you want to reference something in Blueprint it should first be declared in C++. You might find some hacks where you use the reflection system to grab some Blueprint properties but it should not be used in the final product.

2 Likes

1- Create a base c++ class . For example, AActorCTest
2- Create a Blueprint that is child of UActorCTest. You could name it BP_ActorCTest
3- lets create a third class called AMain. Lets supose that this third class has a blueprint child. In order to get access to B_ActorTest create a property :

UPROPERTY(EditDefaultsOnly,BlueprintreadWrite)
TSubClassOf<AActorCTest> bpRef;

now you can access to the blueprint from C++.
If you create a property or function on the blueprint you cannot acces it from c++ unless you use some tricks with reflections, but i think that with this setups there is no need to create properties or functions on BP.

I know this thread was a long time ago but i tried your answer and its giving me an error for TSubClassOf, in ue4 it says “error C2143: syntax error: missing ‘;’ before ‘>’” but i literally copied your answer and just changed the class name to mine. Thanks in advance :slight_smile:

Its BlueprintReadWrite

It still didn’t work even after I changed it.
Here’s what I put:

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
	TSubClassOf<AAccessPoint> bpRef;

AAccessPoint is the parent class of the blueprint I want to access.

Fixed*

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
	TSubclassOf<AAccessPoint> bpRef;
1 Like

Thank you so much!
Although for some reason I can’t spot the difference between the two, what did you change? (Just so in the future ill know what to do)

edit: nvm i see it now :laughing:

1 Like