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
Desire | Syntax |
Return void |
|
Return void, one arg |
|
Return void, two args |
|
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.
Â