Example of Removing a Dynamic Multicast Delegate?

I’m trying to inform my AI characters when their target dies, so I’ve setup a delegate:

LockedOnTarget->EventOnFMCharacterDeath.AddDynamic(this, &AFMPlayableCharacter::OnTargetDeath);

This works fine, and I can use this:

LockedOnTarget->EventOnFMCharacterDeath.RemoveAll(this);

But

LockedOnTarget->EventOnFMCharacterDeath.Contains(this, &AFMPlayableCharacter::OnTargetDeath)

and

LockedOnTarget->EventOnFMCharacterDeath.Remove(this, &AFMPlayableCharacter::OnTargetDeath)

Give cryptic compiler errors . Does anyone have an example of how to use these?

Hello, if you use “AddDynamic” macro to add delegare, you can also use “RemoveDynamic” to remove delegate and “IsAlreadyBound” as equivalent of “Contains”. Functions “Remove” and “Contains” require function as FName, not pointer to member as those macros.

So your code could have these 2 forms…

Using macros:

LockedOnTarget->EventOnFMCharacterDeath.IsAlreadyBound(this, &AFMPlayableCharacter::OnTargetDeath)
LockedOnTarget->EventOnFMCharacterDeath.RemoveDynamic(this, &AFMPlayableCharacter::OnTargetDeath)

Using functions:

LockedOnTarget->EventOnFMCharacterDeath.Contains(this, FName("OnTargetDeath"))
LockedOnTarget->EventOnFMCharacterDeath.Remove(this, FName("OnTargetDeath"))

Both versions compile fine on my end.

1 Like