Here some useful functions for your custom Ability System Component to determine if an ability is Active or not.
bool UKaosAbilitySystemComponent::IsAbilityActive(const FGameplayTagContainer* WithTags, const FGameplayTagContainer* WithoutTags, UGameplayAbility* Ignore)
{
ABILITYLIST_SCOPE_LOCK();
for (FGameplayAbilitySpec& Spec : ActivatableAbilities.Items)
{
if (!Spec.IsActive() || Spec.Ability == nullptr || Spec.Ability == Ignore)
{
continue;
}
const bool WithTagPass = (!WithTags || Spec.Ability->AbilityTags.HasAny(*WithTags));
const bool WithoutTagPass = (!WithoutTags || !Spec.Ability->AbilityTags.HasAny(*WithoutTags));
if (WithTagPass && WithoutTagPass)
{
return true;
}
}
return false;
}
bool UKaosAbilitySystemComponent::IsAbilityActive(const FGameplayAbilitySpecHandle& InHandle)
{
ABILITYLIST_SCOPE_LOCK();
FGameplayAbilitySpec* Spec = FindAbilitySpecFromHandle(InHandle);
return Spec ? Spec->IsActive() : false;
}
bool UKaosAbilitySystemComponent::IsAbilityActive(TSubclassOf<UKaosGameplayAbility> AbilityClass, UObject* SourceObject)
{
ABILITYLIST_SCOPE_LOCK();
FGameplayAbilitySpec* Spec;
if (SourceObject)
{
Spec = FindAbilitySpecByClassAndSource(AbilityClass, SourceObject);
}
else
{
Spec = FindAbilitySpecFromClass(AbilityClass);
}
if (Spec)
{
return Spec->IsActive();
}
return false;
}
This is a very short post, and the functions should make some sense just by reading them.