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?
Sitiana
(Sitiana)
May 21, 2024, 8:23am
2
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