# Delegate with TMap working when it shouldn't

**URL:** <https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615>\
**Category:** C++\
**Tags:** parameters, tmap, unreal-engine, delegates, question, CPP\
**Created:** [May 15, 2017, 4:33am UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615 "2017-05-15T04:33:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjk0104](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mjk0104](https://forums.unrealengine.com/u/mjk0104)\
**Post date:** [May 15, 2017, 4:33am UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615/1 "2017-05-15T04:33:53Z")

</div>

I was having problems with declaring a delegate with a TMap as a parameter, kept getting that I had too many parameters in this declaration:

```
DECLARE_DELEGATE_FiveParams(FOnAlarmJsonParsed, TArray<FIvivaAlarm>, TMap<UObject*, TArray<FIvivaAlarm>>, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>);

```

I was about to wrap the map in a struct, when I thought I’d see if just declaring it as a six parameter delegate would work at all. It did, not only that, but there don’t seem to be any noticeable issues. Here’s the declaration:

```
DECLARE_DELEGATE_SixParams(FOnAlarmJsonParsed, TArray<FIvivaAlarm>, TMap<UObject*, TArray<FIvivaAlarm>>, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>);

```

This seems incorrect… anyone know why it works?

---

<div class="post-metadata">

**Author:** ![Steve\_Robb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Robb](https://forums.unrealengine.com/u/Steve_Robb)\
**Post date:** [May 15, 2017, 3:08pm UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615/2 "2017-05-15T15:08:00Z")

</div>

Hi,

It works because of how the token expansion occurs inside the macro, but I would say it’s not something you should learn to rely on. A better solution would be to typedef your type:

```
typedef TMap<UObject*, TArray<FIvivaAlarm>> FMyMap;

DECLARE_DELEGATE_FiveParams(FOnAlarmJsonParsed, TArray<FIvivaAlarm>, FMyMap, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>, TArray<FIvivaAlarm>);

```

Hope this helps,

Steve

---

<div class="post-metadata">

**Author:** ![Socke81](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/socke81/32/1194535_2.png) [@Socke81](https://forums.unrealengine.com/u/Socke81)\
**Post date:** [May 7, 2018, 3:40pm UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615/3 "2018-05-07T15:40:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve\_Robb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Robb](https://forums.unrealengine.com/u/Steve_Robb)\
**Post date:** [May 8, 2018, 11:48am UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615/4 "2018-05-08T11:48:45Z")

</div>

This trick doesn’t work for _dynamic_ delegates, unfortunately, as UnrealHeaderTool doesn’t understand typedefs. In that case, you should put your map inside a USTRUCT and then pass that instead.

Steve

---

<div class="post-metadata">

**Author:** ![LN1995](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LN1995](https://forums.unrealengine.com/u/LN1995)\
**Post date:** [August 30, 2022, 9:13am UTC](https://forums.unrealengine.com/t/delegate-with-tmap-working-when-it-shouldnt/393615/5 "2022-08-30T09:13:19Z")

</div>

I find it can’t apply to Dynamic Delegate too. Use the UStruct with TMap
