Hey!👋 ubyte.dev just recently launched. It's dedicated towards Unreal Engine 5.

TDelegate and TMulticastDelegate (since 4.26)

November 27, 2022
Lucas Tchikhinachvili
You can now write TDelegate and TMulticastDelegate instead of DECLARE_DELEGATE and DECLARE_MULTICAST_DELEGATE

New in 4.26! TDelegate and TMulticastDelegate

In a nutshell, in 4.26, it's possible to directly use TDelegate instead of these macros (although using these macros might still be preferred): 

DECLARE_DELEGATE
DECLARE_DELEGATE_OneParam
DECLARE_DELEGATE_RetVal
DECLARE_DELEGATE_RetVal_OneParams
DECLARE_DELEGATE_TwoParams
DECLARE_DELEGATE_RetVal_TwoParams
ETC.

TMulticastDelegate uses the same template syntax as TDelegate, and may supersedes the following macros:

DECLARE_MULTICAST_DELEGATE
DECLARE_MULTICAST_DELEGATE_OneParam
DECLARE_MULTICAST_DELEGATE_RetVal
DECLARE_MULTICAST_DELEGATE_RetVal_OneParam
DECLARE_MULTICAST_DELEGATE_TwoParams
DECLARE_MULTICAST_DELEGATE_RetVal_TwoParams
ETC.

Usage example

Instead of writing:

DECLARE_DELEGATE_TwoParams(FTest, UObject* Target, FVector Location)

You can now directly write this, (which is essentially what that macro expanded to):

using FTest = TDelegate<void(UObject* Target, FVector Location)>;  
// or  
typedef TDelegate<void(UObject* Target, FVector Location)> FTest;

Usage table

DesireSyntax
Return void

TDelegate<void>

Return void, one arg

TDelegate<void(bool Arg)>

Return void, two args

TDelegate<void(bool Arg, float Arg2)>

TMulticastDelegate must return void.

Why I prefer this over macros

I think using TFunction's syntax will create more consistency among everything that implies a native-only function signature definition with no editor exposure.

On the other hand, because DECLARE_DYNAMIC_ delegate variants require reflection code to be generated (such as hidden structs, housing all the delegate's arguments) for blueprint VM execution, and an on-the-spot class definition with inlined, non-virtual execution methods, using a macro is extremely neat.

 

cross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram