In this lesson, you will learn how to use FGameplayEffectAttributeCaptureDefinition to pull live attribute data from both the instigator and the target during a custom UGameplayEffectExecutionCalculation.
Why Capture?
When calculating complex effects—like a backstab attack that deals bonus damage based on the attacker's Strength and the target's Armor—you cannot simply look at the attribute values in real-time. Because attributes can change rapidly, GAS provides a "capture" mechanism. This freezes a snapshot of the relevant attributes at the exact moment the GameplayEffect is evaluated, ensuring your math is consistent and thread-safe.
Defining the Captures
To capture these values, we first define them in our execution calculation class. We use a struct to hold our definitions and tell the system exactly which attributes we want to observe and whether we want to capture them from the Source (the ability owner) or the Target (the victim).
struct FMyDamageStatics
{
DECLARE_ATTRIBUTE_CAPTUREDEF(DamageAttribute);
DECLARE_ATTRIBUTE_CAPTUREDEF(ArmorAttribute);
FMyDamageStatics()
{
// Define the Capture: Attribute, Source/Target, Snapshot (bool)
DEFINE_ATTRIBUTE_CAPTUREDEF(UMyAttributeSet, DamageAttribute, Source, false);
DEFINE_ATTRIBUTE_CAPTUREDEF(UMyAttributeSet, ArmorAttribute, Target, false);
}
};
Retrieving the Values
Once defined, you use the FGameplayEffectCustomExecutionParameters provided in the Execute_Implementation method to extract the captured data. You create an FAggregatorEvaluateParameters object to pass in the relevant tags, then pull the value using the definition you created earlier:
void UMyDamageExecCalc::Execute_Implementation(...) const
{
float SourceDamage = 0.0f;
ExecutionParams.AttemptCalculateCapturedAttributeMagnitude(Statics().DamageAttributeDef, EvaluationParams, SourceDamage);
// Now you have the exact snapshot value to use in your formula!
}
By using AttemptCalculateCapturedAttributeMagnitude, you ensure that if the attribute wasn't successfully captured (for example, if the target lacks the specified Attribute Set), your logic won't crash, and you can provide a safe default value.
Key Takeaway: Capture definitions allow you to safely snapshot source and target attributes at the moment of calculation, providing the stable data needed for complex custom damage formulas.