GameplayEffect stacks bugging out when applied with multiple different magnitudes

When applying multiple instances of the same gameplay effect (stacking) with different magnitudes, the total amount will bug out as soon as a different magnitude is added.

More info in steps to reproduce

[Attachment Removed]

Steps to Reproduce
Apply multiple instances of the same gamplay effect like this:

Use different magnitues (eg. first one 20, second one 12)

FActiveGameplayEffectHandle UVAbilitySystemComponent::ApplyGameplayEffectMagnitudeToSelf(
    const TSubclassOf<UGameplayEffect> GameplayEffectClass, float Magnitude, FGameplayEffectContextHandle ContextHandle
)
{
    FGameplayEffectContextHandle EffectContextHandle = {};

    if (ContextHandle.IsValid())
       EffectContextHandle = ContextHandle;

    const FGameplayEffectSpecHandle SpecHandle = MakeOutgoingSpec(GameplayEffectClass, 1, EffectContextHandle);

    if (FGameplayEffectSpec* Spec = SpecHandle.Data.Get())
       Spec->SetSetByCallerMagnitude(FGameplayTag::RequestGameplayTag("SetByCaller.Generic"), Magnitude);

    return ApplyGameplayEffectSpecToSelf(*SpecHandle.Data.Get());
}

Setup the stacking like this:

[Image Removed]

and duration like this:

[Image Removed]

As soon as another stack is applied it will override the magnitude of all other stacks.

Eg.:

  • You add 20, 20, 20 --> 60
  • Add another 12 --> 48 (expected 72)
    [Attachment Removed]

Hi there,

I was able to reproduce this in 5.7, 5.6 and 5.5.

I believe that this is intended behaviour for the stacking effect. When applying a GameplayEffectSpec without stacking a new instance is added to the ability system. However with stacking the previously applied spec gets updated with the new instance. When checking the value of the attribute it will only use the magnitude in the most recently applied spec.

- Louis

[Attachment Removed]

Hi,

Thanks for your answer.

So if i want to stack the duration as well as the magnitude there is currently no way to do this?

Because if i use a seperate instance instead of stacking i have the issue that the durations are running in parrelel for each stack.

So even with 7 effects they would be finished after 60 seconds.

The intended behavior would be that each stack stays for 60 seconds. So 7 stacks would add up to 7 minutes.

[Attachment Removed]

I’ve had a deeper look into this. Unfortunately, no this doesn’t seem to be achievable by default.

You would need to create some kind of workaround for this limitation. For example you could modify your ApplyGameplayEffectMagnitudeToSelf

to store the intended magnitudes in an array and remove an element each time a stack expires. Finally whenever the function is called or a stack expires, overwrite the GameplayEffectSpec’s magnitude with the aggregate of the array.

- Louis

[Attachment Removed]

Thanks for your answer.

We settled on a different solution now.

Instead of one gameplay effect that stacks and drains it duration we now split it up into 2 gameplay effect (one draining and one adding) that are not stacking.

You can close this question for now

[Attachment Removed]