How-To: Set Up Attributes

Goal: define attributes on UCrimsonAttributeSet and react to them changing.

Prerequisites
Quick Start step 2, which creates the set.
Attribute sets are C++ only
Blueprint cannot declare FGameplayAttributeData. This is a GAS constraint, not a plugin one. Everything downstream - reading, clamping via effects, binding UI - works in Blueprint.

1. Add an attribute

The pattern is four parts: the FGameplayAttributeData member, ATTRIBUTE_ACCESSORS, an OnRep_ function, and a DOREPLIFETIME_CONDITION_NOTIFY entry. Quick Start step 2 has the complete file; copy it and rename.

Why REPNOTIFY_Always
GAS needs the notify even when the replicated value is numerically unchanged, because the prediction system may have already applied the same value locally. Using the default REPNOTIFY_OnChanged silently drops those.

2. React to a change

On the ASC, use Get Gameplay Attribute Value Change Delegate is C++ only; in Blueprint use the engine's Async Task: Wait Attribute Change node, or bind a gameplay effect to drive a tag you can listen for.

Verify
Apply an effect that changes the attribute and confirm the handler fires on both server and owning client.

3. Clamp it

Clamp in PreAttributeChange on your set - not in the effect - so every path that touches the attribute is covered.

cpp
void UMyCombatSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
if (Attribute == GetStaminaAttribute())
{
NewValue = FMath::Clamp(NewValue, 0.f, 100.f);
}
}
Verify
Overspend the attribute and confirm it floors at zero rather than going negative.

See also

  • Quick Start
  • How-To: Add Ability Costs