Subscribing to event

Hello everyone,

I’d like to request help, using blueprint events in c++.

I have a class, that I want to subscribe to another class’s blueprint event dispatcher.
this is my subscribing function



void UTemplateBaseSkill::Subscribe(class ATemplateCharacter* MyOwner)
{
	MyOwner->
}


Can I access the BindEventTo function in c++? If so, please tell me?

And this is the event I want to subscribe:



UFUNCTION(BlueprintImplementableEvent, Category = Skill)
			void Event();


I’ve seen some things resembling to events in the StrategyGame example but I couldn’t make it out completely.

Thanks in advance.

The term BlueprintImplementableEvent is a bit misleading I think. It basically acts as a specifier to allow for blueprint overrides of functions. So in your case you can have a blueprint that gives the function “Event” a body that is executed whenever the function is called.

The equivalent of actual Events in C++ is called Delegates. You can find the documentation for them here:

If you create multicast delegates and mark them BlueprintAssignable you can also use them from blueprints.

greetings
FTC

1 Like

Thank you very much! :slight_smile:

Multi-Cast delegates do work just the way events do. But from your link, I could find another link to events, and now it works flawlessly.

Thank you again!

edit –

In case anyone else got stuck like me with c++ events, and found this post, here’s how I’ve done it:

Class with event:



**.h:**
DECLARE_EVENT_OneParam(ATemplateCharacter, QPressed, FString)

UCLASS()
class ATemplateCharacter : public ACharacter
{
	...

	/*Skill held by the character*/
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Skill)
		class UTemplateBaseSkill* QSkill;

	/*Event when Q key is pressed*/
		QPressed FirstEvent;

	/*Function that will fire event*/
	UFUNCTION(BlueprintCallable, Category = Skill)
		void Fire();
};

**.cpp:**
#include "BaseSkill.h"

ATemplateCharacter::ATemplateCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	// Create Skill and call it's subscription function, so that it can subscribe to all the necessary events (the skill gets pointer to owner) 
	QSkill = NewNamedObject<UTemplateBaseSkill>(this, TEXT("QSkill"));
	QSkill->Subscribe(this);
}

void ATemplateCharacter::Fire()
{
	FirstEvent.Broadcast("jack");
}


Class subscribing to event:



**.h:**
	//Using skill
	UFUNCTION(BlueprintCallable, Category = Skill)
		void Use(FString Caller);

	// function for subscribing
	UFUNCTION(BlueprintCallable, Category = Skill)
		void Subscribe(ATemplateCharacter* MyOwner);

**.cpp:**
void UTemplateBaseSkill::Subscribe(class ATemplateCharacter* MyOwner)
{
	MyOwner->FirstEvent.AddUObject<UTemplateBaseSkill>(this, &UTemplateBaseSkill::Use);   //this is the worst :D
}

void UTemplateBaseSkill::Use(FString Caller)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(caller));
}


2 Likes