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"

How to add a interface function to a multicast delegate?


I want to extend my actors with an event which gets broadcasted by an other actor's multicast event.

For that I made an interface to ensure that the receiving Actor implements the right function with the right signature. The receiving actor just has to register this function to the broadcasting actor's multicast delegate. I know I can use GetAllActorsWithInterface. I don't want to use it because it doesn't perform well with 1000s of actors.

Since the interface is an object I try to use AddUObject but can't get it to work. I just get:

error C2338: You cannot use UObject method delegates with raw pointers.

Hope someone can point me in the right direction.

 DECLARE_MULTICAST_DELEGATE_TwoParams(FOnMyEventSignature, int32, bool);
 class GAME_API ABroadcastingActor : public AActor
     void RegisterActor(AActor* Actor)
     TArray<FOnMyEventSignature> MyEventDelegates;
 void ABroadcastingActor::RegisterActor(AActor* Actor)
     IMyInterface* Interface = Cast<IMyInterface>(Actor);
     if (Interface)
         FOnMyEventSignature OnMyEvent = MyEventDelegates[0];
         OnMyEvent.AddUObject(Interface, &IMyInterface::OnMyInterfaceFunction);
 class IMyInterface
     void OnMyInterfaceFunction(int32 MessageID, bool IsActive);
Product Version: UE 4.7
more ▼

asked Jun 16 '15 at 06:30 AM in C++ Programming

avatar image

58 3 8 7

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

1 answer: sort voted first

Unreal engine's interface support is very limited. Either you cast it to the "UObject" class your actor inherits or you make an interface that takes a delegate reference and register it in your actor instead with the "UObject" pointer (i.e. the "this" keyword). The latter is probably the best design.

more ▼

answered Aug 12 '15 at 11:02 AM

avatar image

848 124 112 138

(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