How to declare DYNAMIC MULTICAST delegate with TMap?

While this code works well

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTestDelegate, TArray<int32>, ParamName);

I can’t do that with TMap

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTestDelegate, TMap<int32, int32>, ParamName);

Why? DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam is marcro and TMap<int32, int32> has comma inside. So we can’t use that inside this macro. Preprocessor thinks int32> is next macro parameter (not an template parameter).

What I try?

#define COMBINE(a, ...) a, __VA_ARGS__
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTestDelegate, COMBINE(TMap<int32, int32>), ParamName);

Not a chance:

error : Unrecognized type ‘COMBINE’ - type must be a UCLASS, USTRUCT or UENUM

typedef TMap<int32, int32> FMyMap;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTestDelegate, FMyMap, ParamName);

Not a chance and here:

error : Unrecognized type ‘FMyMap’ - type must be a UCLASS, USTRUCT or UENUM

So, the problem in Unreal Header Tool, that tool has no possibilities to bypass this trick(s).
I wish the UHT understood typedef or using keywords in parsing algorithms.

What do you think?

1 Like

I haven’t tested it. But, I found it on a tutorial website.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( FGenerateMyDataDelegate, const TArray<uint8>&, MyData );

https://usagi.hatenablog.jp/entry/2018/08/17/041355

The typedef trick works with normal MULTICAST_DELEGATEs, but it seems that it doesn’t work with DYNAMIC_MULTICAST_DELEGATEs. Probably something with macro and UHT black magic.

I usually workaround it by creating a USTRUCT() with a TMap inside. Not the most elegant solution, but it works.

I’m trying t his solution, but unfortunately it’s not working. I am getting this error: Any ideas?
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCSOnFindSessionsCompleteOther, const FSOnlineResult& SessionResults);
Error (active) E0077 this declaration has no storage class or type specifier
Unrecognized type ‘FSOnlineResult’ - type must be a UCLASS, USTRUCT or UENUM
USTRUCT(BlueprintType)
struct FSOnlineResult
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadWrite)
TMap <int, FBlueprintSessionResult> SessionResults;
}

I’m trying t his solution, but unfortunately it’s not working. I am getting this error: Any ideas?
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCSOnFindSessionsCompleteOther, const FSOnlineResult& SessionResults);
Error (active) E0077 this declaration has no storage class or type specifier
Unrecognized type ‘FSOnlineResult’ - type must be a UCLASS, USTRUCT or UENUM
USTRUCT(BlueprintType)
struct FSOnlineResult
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadWrite)
TMap <int, FBlueprintSessionResult> SessionResults;
}

I have found how to hack Unreal Header Tool. A now it is possible to use TMap in multicast delegates legally, but with a lot of very black magic. Look here :slight_smile:

  1. We should declare type alias to use it in macros.
  2. We just can use DECLARE_DYNAMIC_MULTICAST_DELEGATE_*, but you must add comment at line above with backslash to cheat the UHT (compiler will ignore this line, but UHT is not)
  3. But we must declare delegate manually with TMap type alias to actually create symbols.
  4. Also we have to add macro from *.generated.h with generated info about this delegate (Look at red font in code example)
  5. And finally we should #pragma disable warning 4010 to complile this code/get rid of warning.

This delegate can be used in Blueprints and C++. Try! :slight_smile:

2 Likes