Gameplay Ability Plugin: Cannot derive gameplay effect stats from Source actor attributes for cooldown

I’ve been wrestling for a few days about why this isn’t working.

I have a character class, MyCharacter, with an Ability System Component. It also has an attribute set, we’ll call it HealthSet, with attribute CurrentHealth inside.

I have created an ability “Shoot” that has gameplay effect “TestCooldownEffect” as its cooldown effect. Cooldown effect is set to derive its duration from the CurrentHealth value of the effect source. However, doing so causes the ability to only evaluate once, and be stuck in perpetual cooldown forever. Oddly, setting the effect to derive from the Target’s CurrentHealth makes it work correctly. This is odd because the source and the target are the same actor in this case!

This almost seems like an engine bug.

For those lost souls, I found the answer.

The function FGameplayEffectContext::AddInstigator(class AActor *InInstigator, class AActor *InEffectCauser) in gameplay effect types takes the Instigator, in this case MyCharacter and saves it. This is considered the source in future calculations for the ability. However, during this process it attempts to cast the instigator to the Interface IAbilitySystemInterface and use the one built-in function “GetAbilitySystemComponent” to get a reference to the component. In my case, MyCharacter didn’t implement that interface! So nothing happened and it failed silently.

Yet when MyCharacter is evaluated as the Target of the effect, it doesn’t matter that the class doesn’t implement IAbilitySystemInterface.

This seems like odd behavior, but at least I know the reason.