Can't declare delegates : definition not found

Hello,

Just put my nose into C++ coming from blueprints. I can’t figure out why DECLARE_DELEGATE generates errors. More precisely, I’m doing the following in a character.h file (public) :

DECLARE_DYNAMIC_MULTICAST_DELEGATE_Three_Params(TheName, int32, a, int32, b, int32, c);

And for some reason, Visual Studio tells me that the macro is not defined. If I Ctrl+Click on it, it still redirects me to the Delegates/DelegateCombinations.h file

Thank you !

You have a typo

the proper way to declare a 3 parameter delegate is like this

DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FMyDelegate, int32, a, int32, b, int32, c);

There is no underscore between Three and Params. It’s a mix of snake case and camel case. It’s a bit confusing.

My bad. It’s a typo I made just here in the post.

The example I gave compiles fine. Can you show me your output error?

Post the header file if you can, maybe the error is elsewhere line a missing ; in the line before

MyCharacter.h (3.9 KB)

Move the UEMUM Declaration out of the UCLASS and above it. Delegete declarations are usually up top too but not mandatory.

It compiles successfully

Okay, I wanted to republish a version of the .h cleaned up, but you replied too fast.
Unfortunately, moving the UENUM to the top didn’t fix it (but thanks by the way); here is my current file, which I just ran. I have the issue " declaration has no storage class or type specifier " for each DECLARE, which are underlined in red.
MyCharacter.h (3.6 KB)

Your file compiles fine after moving the UENUM macro out of the UCLASS . Do not look at intellisense when it comes to delegates, it’s basically a red hearing. If you regenerate your project the underlines will go away.

The file generates no problem. Compile it and run refresh visual studio from within unreal

No errors. The green underlines are ok as delegates do not have implementations in the cpp file they are only declared in the header & later bound and called in the cpp.

Indeed, I had to regenerate the solution files. Maybe I should open another question for that, but what exactly does this provide ? Why didn’t it work before generating the solution files ?

Unreal doesn’t work on pure c++. It uses a “bridge” file in the form of the .generated files. These probably do some black magic with epic’s custom macros so that the engine can stitch itself together making c++ work with blueprints.

It’s a bit awkward & messy and it’s unfortunately a quirk of the engine. Not much more I can add. I’m sure an Epic engineer could explain it in detail.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.