Custom Event not being displayed

Could someone please tell me what I am doing wrong?

I created a simple class:


UCLASS(ClassGroup = Components, meta = (BlueprintSpawnableComponent))
class UInteractableComponent : public UBoxComponent {

and within that class I want to create an event that when called via the C++ code, will fire an event in blueprints:


UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "Interaction Began"))
	virtual void OnInteractionBegin(AActor* actor);

The problem is that even though I can add my component to a new blueprint, my custom event on the component doesn’t show up at all in the blueprint for me to add. Is this a bug in the engine or am I doing something wrong?

I’m trying to do the same thing. I need to create custom blueprint event nodes. I’d like to know the right way to implement this too.

I figured it out. Anyone that is having the same issue:

You need to include a BlueprintAssignable property that serves as a delegate. Below is everything you need to get a custom event to show up in your blueprint for a component. You can obviously create your own class, but I am just extending UBoxComponent.



//See Actor.h for other delegate examples
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInteractableBeginSignature, class AActor*, actor);

UCLASS(ClassGroup = Components, meta = (BlueprintSpawnableComponent))
class UInteractableComponent : public UBoxComponent {

//... other cool code here ...

public:
        UFUNCTION(exec, BlueprintImplementableEvent, meta = (FriendlyName = "Interaction Began"))
	virtual void InteractionBegin(AActor* actor);

	UPROPERTY(BlueprintAssignable)
	FInteractableBeginSignature OnInteractionBegin;


With that setup, I now see the event inside of my blueprint whenever I add my component.

Add apparently the only way to fire the event via the C++ side is to call the delegate’s Broadcast function. IE in the example above:


this->OnInteractionBegin.Broadcast(GetCharacter());

Kind of crazy. Hopefully this is just an oversight when working with components and will be fixed in the engine soon.

A BlueprintAssignable is the correct way to do this because it is a multi-cast delegate that allows other classes to register to be informed when the delegate is fired.

BlueprintImplementableEvent is how to expose a function to be overriden by subclasses of the object. When Components can be subclassed created via blueprints, then a BlueprintImplementableEvent would be how to override the behavior in the blueprint.

You can see examples of how this work with something like UPrimitiveComponent::DispatchMouseOverEventswhere when we call both ReceiveActorEndCursorOver and broadcast a OnEndCursorOver for the actor, but we only broadcast OnEndCusorOver for the component.

Thanks for the reply Marc and that does make sense, but I’m confused about why events dealing with actors don’t need a delegate. I have seen several examples on custom events created by Epic and they seem to be able to fire the event directly without using a delegate. I guess I’m just confused with why events are fired differently just because of the class it extends.

Can you provide an example of a case so I can make sure I’m giving you an accurate answer?

In general, if the event is occurring to the object within which the event is placed in then you aren’t (generally) binding to a delegate, but rather overriding a virtual function. If the event you are receiving is occurring to another object, that will need to be done through a broadcast delegate.

There may be some “events” that are custom K2Nodes that may be doing specialized behavior, but in general what I described should be how our events work.

The one that comes to mind is the battery tutorial. When the player picks up a battery in the level the C++ code fires a Pickup event that is received by the blueprints and acted upon. I felt my component class was doing the same thing. When my player controller received input I was calling a function to fire the event. I guess the difference is that everything was done in the character class in the demo? I can’t remember exactly.