is it possible to trigger a Blueprint event from C++?

I’m almost certain the answer is “no,” since blueprint doesn’t have C++ headers, but it seems like this is the sort of thing that should be easy to do: I have an ActorComponent blueprint with some event I want to access, in this case something called EventUse. Whenever the player tries to use an object, in C++ the AMyCharacter can get a reference to the ActorComponent that has the Use event as a TSubClassOf<UActorComponent>, but since the functionality I need is in a blueprint class, not a C++ class, I don’t think I can do something like Cast<BlueprintComponent>(ActorComponent).

So is there a solution? Given a component that has blueprint events, it seems like you should be able to trigger those events from C++, but I’ve been googling for some time and it seems like the whole system was designed to go from C++ to blueprint, not vice-versa.

If your event is blueprint type, but declared in your header you can attach to each both blueprint and C++ functions:

UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Test", meta = (DisplayName = "My Test Event"))
void MyTestEvent(float CurrentHealth); // Do something C++ when this get called...

And to get a copy of a blueprint from C++ from a TSubClassOf<> field, you can do something like:


TSubclassOf<UMyBlueprintClass> MyBlueprint;


auto MyPointer = NewObject<UCOMPONENTTYPE>(this->MyBlueprint.GetDefaultObject()->StaticClass());

That creates a new object though. If you want to get an Actor from world you have to use one of the GetActorOfClass functions and then cast.

Hmm… even after compiling I can’t seem to get at the event in blueprint; to be clear, would this work if the two are scoped differently? That’s the big mental hurdle I’m trying to overcome, the dialogue system has one inheritance hierarchy (uactorcomponent>bpc_dialogue), and my event messaging system goes through a different chain (uactorcomponent>morpheme>talkmorpheme). Adding an event to uactorcomponent just for this seems silly, but wouldn’t any BlueprintImplementableEvent require a common class between the two components’ scope?

Once your blueprint, instance of your own C++ class, gets the event called. It can dispatch the event to the blueprint world. Using that little “]” on top of the the red event node you’ve created. Than any other blueprint can receive the blueprint event dispatched, doesn’t matter the class they are.

Blueprint’s event dispatchers are what you want to attach to your C++ event if you don’t want to change someone else’s code or have direct references to everything in the level which would be bad design anyway.

Ooh okay, I think I see what you mean… by “]” you mean the output delegate node, right? If that’s the case, would that imply that I’d need a second system in charge of instructing blueprints to register/unregister from the dispatcher, to ensure that trying to run the Talk event on a single blueprint didn’t cause every single speech blueprint to play its line at once?

If you are trying to implement someone else’s package, would be easier if the developer provides the needed events to you.
He provides an event called “Talk” and you attach it to an event dispatcher which gets called by your other blueprint components.

And no, once you want your character to ‘talk’, attach to the dispatcher then call it; detach from dispatcher right after…

That makes perfect sense, thank you for the patient explanation- this is the first time I’ve had to dig deeply into blueprints, so this really helped! :slight_smile: