Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Creating an event on an ActorComponent in C++ for Blueprints

Hello! :)

What I want

I'd like to have actors in my scene who can react to a custom event I defined in C++. Small example the player stands next to a button and presses it. I want to fire the event from my C++ code and want to react to it in a blueprint.

What I did

I created a class, derived from UActorComponent, like that:

 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class NOIR_API UMyUsableObject : public UActorComponent
     // Sets default values for this component's properties
     // Called when the game starts
     virtual void BeginPlay() override;
     // Called every frame
     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
     UFUNCTION(BlueprintImplementableEvent, Category="Interaction", meta=(DisplayName = "On Used ~ Player wants to use this object"))    
     void OnMyStuffUsed();    

This is how I try to fire the event in C++:

         TArray<UMyUsableObject*> usable_components;
         bool found = false;
         for (auto component : usable_components)
             UE_LOG(LogTemp, Warning, TEXT("Found component, running event!"));
             found = true;

The C++ side compiles without warnings or errors, the code is actually being executed.

I created a blueprint, consisting of a StaticMeshComponent and added my component to it: alt text

What I expect

I expect the event to be available in the blueprint editor of my actor (similar to other events, like 'Event BeginPlay').

What actually happens

The event can't be found, independent of context sensitivity/search phrase: alt text

What I tried

There are a lot of different answers to this question online, most of them rather old, and none of the answers helped me achieve what I want. For instance, I tried creating a dynamic, multicast delegate but wasn't able to register to the event in blueprint. No errors occured, it simply didn't execute when I used OnMyStuffUsed.Broadcast().

I also tried dragging "MyUsableObject" from the list of variables on the left side to see if the event is only available on the component object directly - didn't appear in there either.

I tried restarting everything, no difference.

If I missed something or I'm expecting things to work in a way they don't, please tell me.

Product Version: UE 4.17
more ▼

asked Aug 19 '17 at 02:59 PM in C++ Programming

avatar image

6 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I just solved it myself. Using a DYNAMIC_MULTICAST_DELEGATE is the right way here, I think i simply connected it the wrong way. Here's how I did it:

My code looks like the following:


     UPROPERTY(BlueprintAssignable, Category = "Interaction")
     FOnMyStuffUsed OnMyStuffUsed;

Firing the event:


Binding the event in Blueprint:

alt text

more ▼

answered Aug 19 '17 at 03:43 PM

avatar image

6 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question