In this lesson, you will learn how the Gameplay Ability System (GAS) intelligently separates an Attribute’s permanent "Base Value" from its transient, modified state.
The Two-Layer Architecture
When you work with FGameplayAttributeData, you are not just looking at a single floating-point number. Behind the scenes, GAS maintains two distinct values for every attribute:
- Base Value: The persistent, "truth" value of the attribute. This is what you set when a character levels up or equips permanent gear.
- Current Value: The dynamic value that reflects the Base Value plus any active
GameplayEffectmodifiers (like buffs, debuffs, or status ailments).
This separation is critical because it allows the system to calculate the final stat without permanently destroying the original data. If a character has a Base Health of 100 and receives a +20 "Temporary Shield" effect, the Current Value becomes 120, but the Base Value remains 100. Once the effect expires, GAS automatically reverts the Current Value to the Base Value.
Synchronizing via Attribute Sets
You don't manually track these changes. Instead, you interact with them via your UAttributeSet. When a GameplayEffect is applied, the AbilitySystemComponent calculates the new Current Value and triggers the PostGameplayEffectExecute function within your Attribute Set.
Here is how you typically access these synchronized values in your PreAttributeChange logic to ensure your stats stay within valid ranges:
void UMyAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
// Ensure the Current Value never exceeds the Base Value defined by the Attribute Set
if (Attribute == GetMaxHealthAttribute())
{
NewValue = FMath::Clamp(NewValue, 1.0f, 1000.0f);
}
}
By overriding PreAttributeChange, you intercept the synchronization process before the Current Value is finalized. This allows you to apply clamping, such as ensuring Health never exceeds Max Health, while keeping the underlying math clean and predictable. The system handles the "cleanup" of these modifiers automatically as effects expire, ensuring your character's stats are always perfectly in sync with their current gameplay context.
Key Takeaway: GAS maintains a clear distinction between the permanent Base Value and the transient Current Value, allowing you to layer temporary modifiers on top of your character’s stats without permanently altering their underlying data.