How to use Delegate.Contains?

Hello all

I am working on a project using Delegates but I am still pretty new to c++ and have no experience using delegates in it. There is one part where I am checking to see if an object (and its function) are already apart of a delegates involved list to avoid errors from occurring if the same object is being added to the delegate.

The problem is that I can’t seem to figure out what needs to be put into the delegate.contains parameters. It appears to have the same parameters as the delegate.addDynamic macro, but the code does not compile when I do this. My best guess is that I somehow need to convert the function name to FName but I’m not sure on how to do this either. Any attempts to find either solution has come up empty. Can anyone here help?

Why no reply, I am suffering the same problem.
I want to check weather my one parameter multicast dynamic delegate contains the same function. But there’s very little if not, no information on this topic online.
Can anybody help?

Why do you want to check that? The macros AddUniqueDynamic and RemoveUniqueDynamic exist so that you don’t have to manually check

1 Like

You can use this to check yourself

if(!OnUpdateProcess.IsAlreadyBound(this, &AUCharacter::UpdateStamina))
{
}

You can also use Add unique instead of checking yourself, this will ensure the function is not already bound

OnUpdateProcess.AddUniqueDynamic(this, &AUCharacter::UpdateStamina);
1 Like

Thanks that works! KaidoomDev including
So simply put, use:

// for non-dynamic I believe: :expressionless:

Delegate.Contains(this, FName(TEXT(UpdateStamina))); 

// to check:

Delegate.IsAlreadyBound(this, &AUCharacter::UpdateStamina); 

//to add weather it have been or not:

Delegate.AddUnique(this, &AUCharacter::UpdateStamina); 

//to check and if wasn’t subscribed, so add and vise versa:

Delegate.AddUniqueDynamic(this, &AUCharacter::UpdateStamina); 
1 Like