[By Design] Blueprint DECLARE_DYNAMIC_DELEGATE Macro Stops at 8 parameters

Whoever added the macros for creating dynamic delegates stopped at eight parameters. Is there any reason why more parameters weren’t added?

Here are the interesting places.

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Runtime/Core/Public/Delegates/DelegateCombinations.h

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Runtime/Core/Public/Delegates/DelegateCombinations_Variadics.h

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Programs/UnrealHeaderTool/Private/HeaderParser.cpp

Here are the edits to add support for 62 parameters.

http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations.h
http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations_Variadics.h
http://tagenigma.com/unreal/DelegateGeneration/HeaderParser.cpp

See comment below for console app that generates macros for up to 62 parameters.

While this is no technical answer, I think having that many parameters gets unwieldy in any situation. An alternative is to use a wrapper struct to pass any amount of parameters using the OneParam variant.

See for example the ComponentHit or Overlap signatures that use a FHitResult as a parameter to pass multiple variables.

In my case I’m actually going from an FStruct to individual parameters to simplify how many steps are in the blueprints.

The existing code requires a ton of BreakToParameters nodes which over complicates the blueprints.

I created a C# console program to generate up to a configurable number of parameters:
http://tagenigma.com/unreal/DelegateGeneration/Program.cs

Here is the generated DelegateCombinations_Variadics.h generated up to 50 parameters:
http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations_Variadics.h

Here’s a unit test.

DECLARE_DYNAMIC_DELEGATE_TenParams(FDelegateOnSuccessTest, int32, a1, int32, a2, int32, a3, int32, a4, int32, a5, int32, a6, int32, a7, int32, a8, int32, a9, int32, a10);

I’m getting an error:

Unable to parse delegate declaration; expected 'DECLARE_DYNAMIC_DELEGATE' but found 'DECLARE_DYNAMIC_DELEGATE_TenParams'.
2>Error : Failed to generate code for ExampleProjectEditor - error code: OtherCompilationError (5)

Looks like I also need to generate DelegateCombinations.h … okay.

Time to start using version control.

I created a C# console program to generate up to a configurable number of parameters:

Here is the generated DelegateCombinations_Variadics.h generated up to 50 parameters:
http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations_Variadics.h

You can right click any struct pin and split it, reducing number of steps back to original

Why don’t you submit that to Epic? :slight_smile: But you need to prepare your code to cooperate with rest of UE4 tools, so it would feel seemless

In my case I’m trying to mirror a Java API and I will smite this parameter limitation.

That’s the plan.

Here is the generated DelegateCombinations_Variadics.h generated up to 50 parameters: http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations_Variadics.h

Here is the generated DelegateCombinations.h generated up to 50 parameters: http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations.h

I created a C# console program to generate up to a configurable number of parameters: UnrealTools/Program.cs at master · tgraupmann/UnrealTools · GitHub

Sweet now it works! The unreal header tool needed to register the newer parameters.

http://tagenigma.com/unreal/DelegateGeneration/HeaderParser.cpp

The technical limitation is 128 parameters. And so 62 is the max number of delegate parameters that can be supported.

Here are the interesting places.

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Runtime/Core/Public/Delegates/DelegateCombinations.h

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Runtime/Core/Public/Delegates/DelegateCombinations_Variadics.h

https://github.com/EpicGames/UnrealEngine/blob/4.9/Engine/Source/Programs/UnrealHeaderTool/Private/HeaderParser.cpp

Here are the edits to add support for 62 parameters.

http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations.h
http://tagenigma.com/unreal/DelegateGeneration/DelegateCombinations_Variadics.h
http://tagenigma.com/unreal/DelegateGeneration/HeaderParser.cpp

And from the screenshot you can see the editor successfully supports a delegate with up to 62 parameters.

Merged into my fork of 4.9 - https://github.com/EpicGames/UnrealEngine/tree/4.9

Unfortunately, coding standards block this change from happening. The staff were worried 20k of macros might negatively impact compile times.