MiddleDesignCommonNot answered yet
You are giving a player character health, mana, and stamina using Unreal's ability system plugin GAS. Each stat has a current and a maximum value, must stay clamped within its valid range, and is driven by gameplay — taking damage, spending mana to cast, draining and regenerating stamina. The implementation should work cleanly with replication and be reusable for AI-controlled characters too. Describe how you would model and modify these stats within GAS. Requirements: the stats live in the framework's own data container rather than ad-hoc variables; values stay clamped on every code path that can change them; all changes flow through the framework's effect system rather than direct assignment; and incoming damage is routed so health is reduced safely rather than written directly.
Define an UAttributeSet with current and max values for each stat, host it on the AbilitySystemComponent, clamp in PreAttributeChange/PostGameplayEffectExecute, and change values only through GameplayEffects with a meta Damage attribute.
- ✗Applying raw damage straight to Health instead of routing it through a meta
Damageattribute - ✗Clamping only in
PreAttributeChange, missing executedInstanteffects - ✗Replicating attributes manually instead of letting the AttributeSet handle it
- →How would you add stamina regeneration that pauses while sprinting?
- →Where would you broadcast a death event when Health reaches zero?
Contents
Architecture
Which GAS pieces are involved
UAttributeSet— oneUCharacterAttributeSetwithHealth/MaxHealth,Mana/MaxMana,Stamina/MaxStamina, and a metaDamageattribute.UAbilitySystemComponent(ASC) — owns the set, stores and replicates attributes.- GameplayEffects — every stat change: damage, healing, regeneration, ability costs.
- GameplayTags —
State.Dead,State.Sprintingfor gating.
Data flow
Ability → CommitAbility (cost = Instant GE on Mana/Stamina)
→ damage: Instant GE sets meta Damage attribute
PostGameplayEffectExecute: Damage → Health -= Damage, Damage reset to 0
PreAttributeChange / PostGameplayEffectExecute: clamp 0..Max
Regeneration: Infinite GE with a Periodic Modifier on Stamina/Mana
Key implementation points
- Declare attributes with
ATTRIBUTE_ACCESSORS, mark themReplicatedUsing. - The meta
Damageattribute is not replicated — it is a transient buffer processed on the server. - In
PostGameplayEffectExecute, readData.EvaluatedData.Attribute, transferDamageintoHealth, clamp the range. - Pause stamina regeneration by adding/removing an Infinite GE keyed on the
State.Sprintingtag.
Trade-offs
- Pros: data-driven changes, free replication, prediction-ready, reusable for AI.
- Cons: more boilerplate than plain
floats; learning curve; debugging through GEs is harder than direct assignment.
Contents