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"

Does declaring delegates require a (dummy) class?

The context

I want to outsource dome delegate declarations to a different header file and include this file any other header file, where I need to use the delegate. But it does not compile saying the delegate is an unknown/unrecognized type. Currently, I need to add a dummy UCLASS to this delegates header file and a .generated.h include statement to make it work.

How to reproduce the compiler error

Create a file Delegates.h with the following content:

 #include "UObject/ScriptDelegates.h"

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSomeDelegateSignature, int32, integer);

Include this file and use it in another class by adding the following property:

 UPROPERTY(BlueprintAssignable, Category="Unreal")
       FSomeDelegateSignature OnCreateAwesomeGameButtonPressed;

My current hotfix

Change the Delegates.h content as follows:

 #include "Object.h"
 #include "Delegates.generated.h"

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSomeDelegateSignature, int32, integer);

     class MYPROJECT_API UDelegates : public UObject

My issue

I don't want to create a new class. And I heard that you dont need to (and that there are examples inside the engine code that proves this). So what am I doing wrong?

Product Version: UE 4.15
more ▼

asked Mar 28 '17 at 12:54 PM in C++ Programming

avatar image

151 5 11 14

avatar image rYuxq Mar 31 '17 at 07:57 AM


avatar image Atheist91 Mar 05 '18 at 04:43 PM

There is an example of how to do such thing in CoreDelegates.h.

Keep in mind tho, that delegates declared like that won't be visible in blueprints.


Oh, nvm. Brainfart. You'd still need a class to declare delegates like that. Just UCLASS wouldn't be mandatory.

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

1 answer: sort voted first

What if you don't create the UCLASS but leave the Delegates.generated.h include?

more ▼

answered Apr 03 '17 at 07:23 PM

avatar image

1k 8 24 28

avatar image rYuxq Apr 03 '17 at 08:18 PM

I already tried that, but that didnt work. I think it regenerates the Delegates.generated.h when I hit build. And when there is no UCLASS, it does not generate the necessary classes anymore

avatar image dachora1 Jan 27 '18 at 12:38 AM

Did you ever figure this out? I'm trying to do the same thing now and don't want a dummy class...

avatar image rYuxq Feb 12 '18 at 08:57 AM

Hmm no, actually not. For now, I am putting stuff like this into a class which will generate reflection code anyway and for that, I choose my "Statics" class (the code where I put all my globally accessible, static functions and variables)...

(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