# How to declare DYNAMIC MULTICAST delegate with TMap?

**URL:** <https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542>\
**Category:** C++\
**Tags:** uht, tmap, unreal-engine, delegates, bug-report, CPP, question\
**Created:** [December 6, 2017, 1:37pm UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542 "2017-12-06T13:37:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![broly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@broly](https://forums.unrealengine.com/u/broly)\
**Post date:** [December 6, 2017, 1:37pm UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/1 "2017-12-06T13:37:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zgzg2020](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zgzg2020](https://forums.unrealengine.com/u/zgzg2020)\
**Post date:** [September 16, 2021, 8:38am UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/2 "2021-09-16T08:38:46Z")

</div>

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](https://usagi.hatenablog.jp/entry/2018/08/17/041355)

---

<div class="post-metadata">

**Author:** ![zompi2](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zompi2/32/937524_2.png) [@zompi2](https://forums.unrealengine.com/u/zompi2)\
**Post date:** [September 16, 2021, 10:27am UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/3 "2021-09-16T10:27:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zgzg2020](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zgzg2020](https://forums.unrealengine.com/u/zgzg2020)\
**Post date:** [September 18, 2021, 11:56am UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/4 "2021-09-18T11:56:19Z")

</div>

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;  
}

---

<div class="post-metadata">

**Author:** ![zgzg2020](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zgzg2020](https://forums.unrealengine.com/u/zgzg2020)\
**Post date:** [September 18, 2021, 11:57am UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/5 "2021-09-18T11:57:00Z")

</div>

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;  
}

---

<div class="post-metadata">

**Author:** ![broly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@broly](https://forums.unrealengine.com/u/broly)\
**Post date:** [November 2, 2021, 8:05am UTC](https://forums.unrealengine.com/t/how-to-declare-dynamic-multicast-delegate-with-tmap/411542/6 "2021-11-02T08:05:07Z")

</div>

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 🙂

 ![351454-photo-2021-07-20-16-04-32.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/0/1e0dd2028f8d1d2b37f8b9ce50921ac4667993a2.jpeg)

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! 🙂
