Declare Delegate in non UE4 class

Hey,

I’m trying to declare a delegate in a class that doesn’t inherit from a UE4 class but I’m getting compilation errors:

error C2143: syntax error : missing ';' before '<class-head>'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C3861: FLoginOK_DelegateWrapper': identifier not found

and here is a sample of my class:

#include "Engine.h"
#include "Delegate.h"
#include "DelegateBase.h"
#include "DelegateCombinations_Variadics.h"
#include "DelegateInstanceInterface_Variadics.h"
#include "IDelegateInstance.h"
#include "IntegerSequence.h"
#include "MulticastDelegateBase.h"
#include "Tuple.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLoginOK); // The error line.

class MYGAME_API AccountManager
{
private:
    FLoginOK LoginSuccess;
};

As you can see I thought the macro definition was not being included so I included everything from the Delegates public module in the engine code to no avail. If I declare that delegate in a different header (with a class that inherits from a UE4 class) and include that header in this class (AccountManager) I am able to use that definition. The AccountManager class (the problem class) was created using the editor’s ‘New C++ class’ wizard.

Any ideas on why I would be getting an error?

OK so my co-worker and I got to thinking that because it wasn’t a UObject inherited header, UE4’s header tool didn’t process it thus the macro didn’t expand properly (or something to that extent). So converting the AccountManager class to a UObject worked. It wasn’t noted in the original question but the AccountManager is a singleton you can look at this to see how to declare a singleton UObject. Here is the revised sample:

#include "Object.h"
#include "AccountManager.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLoginOK);

UCLASS()
class MYGAME_API UAccountManager : public UObject
{
private:
    FLoginOK LoginSuccess;
};

Hi krazzei,

Dynamic delegates are only for use with UObject types. ‘Dynamic’ in this case means that UnrealHeaderTool can parse them and are exposed to the reflection system, and so have runtime type information and can be used as properties.

If you don’t want any of that, then you can use a non-dynamic delegate:

DECLARE_MULTICAST_DELEGATE(FLoginOK);

This should work for any regular C++ type.

Steve

3 Likes

Thanks a lot ! :slight_smile: