Blueprint Implementable Custom Component Events?

I’m trying to create custom actor components which have implementable events. I have a basic unit class and a basic spell class, and I want to be able to create custom blueprints from those to make different types of units and different spells.

I have a few events I want to be able to implement such as “OnCastBegin”, “OnCastSuccess”, and “OnCastFailure” etc. Here’s the full code for my ability’s header class:

#pragma once
#include "KBuff.h"
#include "KAbility.generated.h"
/**
 * 
 */

/*
	TODO:
	- Active Component: the action which happens if the ability is activated. An ability may or may not have an active.
	- Passive Component: the passive effects of the ability. An ability may or may not have passive effects.
*/
class AKBasePawn;

UCLASS(ClassGroup=(Ability), meta=(BlueprintSpawnableComponent))
class KIDSOFTHEWOODS_API UKAbility : public UActorComponent
{
	GENERATED_BODY()

public:
	UKAbility();
	~UKAbility();

	UFUNCTION(BlueprintImplementableEvent, Category = "KAbility")
	void OnCastBegin();
	
	UFUNCTION(BlueprintImplementableEvent, Category = "KAbility")
	void OnCastFail();
	
	UFUNCTION(BlueprintImplementableEvent, Category = "KAbility")
	void OnCastSuccess();
	
	UFUNCTION(BlueprintImplementableEvent, Category = "KAbility")
	void OnTargetHit(const AKBasePawn *Target);

	UFUNCTION(BluePrintCallable, Category = "KAbility")
	void ActivateAbility();

protected:
	AKBasePawn *owningUnit;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "KAbility")
	float castTime;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "KAbility")
	UKBuff *passiveAbility;

};

When I look at the static mesh reference of my blueprint, it has a ton of implementable events such as OnMouseOver, OnClicked, etc. I can’t figure out how to do that for my component.

I found that UPrimitiveComponent does the events I mentioned as follows:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( FComponentBeginCursorOverSignature, UPrimitiveComponent*, TouchedComponent );

//then further down...

UPROPERTY(BlueprintAssignable, Category="Input|Mouse Input")
FComponentBeginCursorOverSignature OnBeginCursorOver;
1 Like

So I found out in order to have component events available to you in blueprints requires a dynamic multicast delegate–or at the very least a dynamic delegate, I haven’t tested whether that works as well.

The code to do this is as follows:

#pragma once
//include headers
#include "UCustomComponent.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FComponentCustomStartSignature);

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class MYGAME_API UCustomComponent : public UActorComponent
{
public:
    UPROPERTY(BlueprintAssignable, Category="Custom")
    FComponentCustomStartSignature OnCustomStart;

};

Do that, and your events should show up under events like in the bottom right corner of the picture.

1 Like

Is there a way to do the same via blueprint?
I mean, a custom blueprint-made component.

Add an Event Dispatcher and copy the Signature from the custom event you created.