In this lesson, you will learn how to control the lifecycle and cumulative behavior of buffs and debuffs within the Gameplay Ability System (GAS) using Duration Policies and Stacking rules.
Understanding Duration Policies
Every UGameplayEffect has a DurationPolicy that dictates how long it persists on a target. There are three primary types:
- Instant: The effect is applied once and immediately removed. It is ideal for one-time events like healing or damage.
- Infinite: The effect persists until manually removed via an
AbilitySystemComponent(ASC) call. This is perfect for passive traits or toggled states. - Has Duration: The effect lasts for a defined
DurationMagnitude(usually in seconds). Once the time elapses, the effect is automatically removed.
Mastering Stacking
Stacking allows you to define what happens when an effect is applied while an instance of it is already active. You configure this in the Stacking section of your Gameplay Effect.
- Stacking Type: You can choose to stack per Source (unique instances per caster) or per Aggregate (all instances of this effect type share the same stack count).
- Stack Limit: This defines the maximum number of times an effect can stack.
- Overflow Strategy: If you reach the limit and try to apply another, you can decide to
Do Nothing,Replace the Oldeststack, orRefresh Duration.
For example, a "Burning" debuff might use a Duration Policy of Has Duration (5 seconds) and a Stacking Type of Aggregate. If a player gets hit by a fire arrow while burning, the stack count increases, and by using the Refresh Duration policy, the 5-second timer resets, keeping the pressure on the player.
// Example configuration logic (conceptual)
GameplayEffect->DurationPolicy = EGameplayEffectDurationType::HasDuration;
GameplayEffect->DurationMagnitude = FScalableFloat(5.0f);
GameplayEffect->StackingType = EGameplayEffectStackingType::AggregateBySource;
GameplayEffect->StackLimitCount = 5;
By balancing these settings, you gain fine-grained control over your game’s balance, allowing for sophisticated mechanics like scaling damage-over-time effects or temporary attribute multipliers that decay predictably.
Key Takeaway: Use Instant effects for one-off changes, Has Duration for temporary buffs, and Infinite for permanent states, while leveraging Stacking rules to determine how multiple instances of these effects interact.