Cast to C++ actor in blueprint actor

I cannot do English well…

I made and spawned an actor class in C++.
How can I cast to spawned actor in blueprint?

Exactly, I want to remove the spawned actor in c++ when the spawned actor in c++ overlap the blueprint actor.

You don’t need to cast to do so, Destroy() is in AActor class and overlap events return actor that hits as AActor* so no need for casting just call a function on it.

As for casting, you can’t cast to Blueprint in C++ as those classes don’t physically exist in C++ code, compiler won’t know what you referencing to. As for C++ classes in blueprint, they are visible as normal blueprint class.

In your case if you try to execute some code on destruction in blueprint, best way to do so would be place it in OnDestroyed event in blueprint, which will be executed when you destroy actor in C++. Don’t need to toy with calling blueprint functions in C++ which would only make code look messy.

Hi there. One thing you can do from your blueprint actor is click the component you want to use to check the overlap and set click the plus symbol next to On Begin Overlap from Events in the details panel. (Pictured below)


Now you should be able to cast to your c++ class from the editor by right clicking and typing “cast to (your class name here)”. From there you can execute whatever you want, assuming the cast is successful. If your c++ class has functions exposed to blueprint, you can even call them by dragging off the “As Your Class Name” pin.

Hope that helps!