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

Hello! :slight_smile:

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
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UMyUsableObject();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// 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;
		act->GetComponents<UMyUsableObject>(usable_components);
		bool found = false;

		for (auto component : usable_components)
		{
			UE_LOG(LogTemp, Warning, TEXT("Found component, running event!"));
			component->OnMyStuffUsed();
			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:

210360-2017-08-19-16-42-50.png

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:

210371-2017-08-19-16-47-49-s-displaystand-blueprint.png

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.

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:

Declaration:

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

Firing the event:

component->OnMyStuffUsed.Broadcast();

Binding the event in Blueprint:

210375-2017-08-19-17-42-49-s-displaystand-blueprint.png

I’m having the same problem. What is “My Usable Object” in your blueprint?