Delegate with TMap working when it shouldn't

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?

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

2 Likes

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

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

1 Like

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