x

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"

Using multicast delegates on a c++ class that is not a UClass

I have declared a multicast delegate in the following fashion in header file

 DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnActivationComplete);
 
 class MyGame_API UMyClassComponent
 {
 };

It shows me the following compilation error in .generated.cpp

 Use of undeclared identifer
 UClass* OuterClass=Z_Construct_UClass_UMyClassComponent();

The above problems still remains but I found a workaround. If I use DECLARE_DELEGATE or DECLARE_EVENT it works on a non UClass class. It allows me to broadcast the event. The problem that I am having now is listening the event in my Actor sub class.

I tried using AddRaw(this, &MyActorSubclass::MyFunction) - but it fails with 'no such method definition for AddRaw'. I dont understand why this fails to compile?? (MyFunction is not a UFUNCTION). Can someone please let me know the correct way of achieving this?

I also tried AddSP() but unfortunately TSharedFromThis is not allowed on Actor sub classes. So cant use this.

EDIT: Updated the question with my most recent findings.

Product Version: Not Selected
Tags:
more ▼

asked Oct 25 '14 at 02:58 PM in C++ Programming

avatar image

Anshul
153 9 12 216

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

1 answer: sort voted first

There are a few issues. You shouldn't prefix your class with U if you are not UObject derived. Since you are naming it UMyClassComponent, then I am assuming you have a UObject based class derived from some UInsertHereComponent. Your error Z_Construct etc, just tells you that you are missing UCLASS / GENERATED_UCLASS_BODY etc. To make delegate work with this setup use AddUObject .

If you have a plain class, not UObject derived, say FMySomething, then the following will work:

 struct FMySomething
 {
     FSimpleMulticastDelegate OnFoo;
     void Callback();
 };
 
 then to Add:  OnFoo.AddRaw(this, &FMySomething::Callback);

Hope this helps.

more ▼

answered Oct 27 '14 at 09:02 PM

avatar image

ttvd
333 20 25 34

avatar image Anshul Oct 28 '14 at 04:11 AM

Thanks! Using AddUObject seems to work fine. I tried all other methods except this one :p.

PS: I should definitely rename my class. It started out as a subclass of USceneComponent but then I converted it into a regular c++ class. The name remained for some reason.

(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