Declare delegate in one header file and use it in other headers

Hello,

I have a very simple query to which I was not able to find an answer from a quick google search. Maybe because its too obvious or its a silly question.

Lets say I have a two classes A and B having their own header and cpp files. I declare a delegate signature in class A’s header file like so DECLARE_DYNAMIC_DELEGATE_OneParam(FGameStateChange, bool, newState); and use it declare a delegate in the same header.

Now I want to reuse this signature to declare a delegate in B’s header file without having to include the A’s header in B’s header.

Any ideas how to do this? Do I have to just declare the same delegate signature in B again?

I hope I did not phrase the question in a confusing way.

Thanks

Look at ActionRPGTypes.h in the ActionRPG source. You make a header that only includes structs, enums, and delegates and include that header in all your classes.

Use UDELEGATE() macro when defining delegates in a shared header file.

Could not find anything about it on the internet, posting this from browsing unreal source code and finding a usage like this.

MySharedHeaderFile.h

#pragma once

#include "CoreMinimal.h"
#include "MySharedHeaderFile.generated.h"

UDELEGATE()
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMyDelegateSignature);
4 Likes

Thank you for sharing this, I had a challenging evening last night going around in circles wondering what I was missing. Stumbling across your reply to this post resolved the issue for me - thank you :slight_smile:

1 Like