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);
UCLASS()
class MYPROJECT_API UDelegates : public UObject
{
GENERATED_BODY()
};
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?