Bind multicast delegate with Add()

Hello.

I want to bind a method in a component to the OnTakeAnyDamage event of the owning Actor.

OnTakeAnyDamage as defined in Actor.h:

UPROPERTY(BlueprintAssignable, Category="Game|Damage")
FTakeAnyDamageSignature OnTakeAnyDamage;

FTakeAnyDamageSignature:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams( FTakeAnyDamageSignature, float, Damage, const class UDamageType*, DamageType, class AController*, InstigatedBy, AActor*, DamageCauser );

The method I want to bind in the component:

UFUNCTION()
void TakeDamage(float Damage, UDamageType* const DamageType, class AController* InstigatedBy, class AActor* DamageCauser);

Now, in the constructor of the component I want to bind the TakeDamage method to the owning actor’s OnTakeAnyDamage delegate.

I can access GetOwner()->OnTakeAnyDamage, which has an Add() method, but nothing I try works.

What’s the syntax for this?

Thanks.

You need to use the AddDynamic macro for dynamic delegates, the macro simply resolves to a call to the __Internal_AddDynamic() method of a dynamic delegate, but unfortunately Intellisense usually won’t suggest it to you.

Here’s sample usage from CharacterMovementComponent.cpp in the engine source:

UpdatedComponent->OnComponentBeginOverlap.AddDynamic(this, &UCharacterMovementComponent::CapsuleTouched);

I had some trouble when I first started using delegates because I had a misunderstanding about how they were called. Hope this helps: link text