Syntax For Binding to an Engine Event Class

I’m attempting to bind the FLevelActorDeletedEvent Class in UEngine.h to a member function in my object class. This is the Declaration in Engine.h:

/** Editor-only event triggered when actors are deleted from the world /
DECLARE_EVENT_OneParam( UEngine, FLevelActorDeletedEvent, AActor
);
FLevelActorDeletedEvent& OnLevelActorDeleted() { return LevelActorDeletedEvent; }

Here’s my attempt to bind to the DeleteMSComps function in my class:

if (GEngine)
	GEngine->FLevelActorDeletedEvent::Add(*this, &ATBSMoveSpaceArea::DeleteMSComps);  

I get the error:

…‘TBaseMulticastDelegate::Add’: no overloaded function takes 2 arguments

I’m not sure how to properly bind to this event class in UEngine.h. Any advice? Thank you!

First of all delegate is only a type which stores pointer (or pointers in case of multicast) and which can execute a call to stored function. In other word it needs object variable of that delegate, which store information about function in memory and send out calls to them. So you can not bind to delegate type as you attempting to do.

the function pasted below:

FLevelActorDeletedEvent& OnLevelActorDeleted() { return LevelActorDeletedEvent; }

Is the one who gives you access to the delegate object which you can bind to, so it should look like this:

GEngine->OnLevelActorDeleted().Add(*this, &ATBSMoveSpaceArea::DeleteMSComps);

2nd issue is the one that causes the error. Function you trying to use is to bind another delegate to this delegate not to bind functions direly, not to mention it seems ot be deprecated too. There whole set of Bind (singlecast) and Add (Multicast) function that bind specific type of functions, check API refrence:

https://api.unrealengine.com/INT/API/Runtime/Core/Delegates/TBaseMulticastDelegate_void_Para-/index.html

Since you trying to bind actor which is UObject you should use AddUObject function instead

GEngine->OnLevelActorDeleted().AddUObject(*this, &ATBSMoveSpaceArea::DeleteMSComps);

3rd issue is * in *this. * converts pointer to standard type by creating new copy of the entire object, which is something that you should never do with UObject. You would get error feather on because of it as function we using here only accepts pointer. So you should have this:

 GEngine->OnLevelActorDeleted().AddUObject(this, &ATBSMoveSpaceArea::DeleteMSComps);

Make sure function you pointing have matching argument types in case of FLevelActorDeletedEvent, it should be AActor* so you function should be declered like this

void DeleteMSComps(AActor* DeletedActor);

Thank you! I got it working, and am starting to understand a little better.