Checking if Gameplay Ability is Active.

Here some useful functions for your custom Ability System Component to determine if an ability is Active or not.

Relevant Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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.