Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.21
more ▼

asked Mar 11 '19 at 07:48 PM in C++ Programming

avatar image

7 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:


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);

more ▼

answered Mar 11 '19 at 08:50 PM

avatar image

35.8k 927 169 1105

avatar image Lakuenza Mar 12 '19 at 03:46 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question