Course contentsShow
← Unreal Engine Game Development
Lesson 649 of 8809. Gameplay Ability System (GAS)Free lesson

Creating Custom Gameplay Execution Calculations

Develop custom C++ classes inheriting from UGameplayEffectExecutionCalculation to perform complex mathematical logic beyond simple static attribute modifiers.

In this lesson, you will learn how to move beyond static attribute modifiers by implementing UGameplayEffectExecutionCalculation to perform complex, multi-step math when applying Gameplay Effects.

While FGameplayModifierInfo is perfect for simple "Add 10 Health" operations, it fails when you need dependencies—like calculating damage based on an attacker’s Strength, a defender’s Armor, and a random critical hit multiplier. This is where Execution Calculations (or ExecCalcs) come in. They allow you to execute arbitrary C++ logic during the application of an effect.

Structuring the Calculation

To build one, create a C++ class inheriting from UGameplayEffectExecutionCalculation. Inside, you will override Execute_Implementation. This function provides you with the FGameplayEffectCustomExecutionParameters, which acts as your gateway to the Ability System Component (ASC).

Unlike standard modifiers, ExecCalcs let you capture "Backing Attributes." You must define an internal FPropertyCaptureDefinitions struct to capture the values of attributes at the exact moment the effect is applied:

// Define what attributes we need for the math
struct FDamageStatics {
    DECLARE_ATTRIBUTE_CAPTUREDEF(Armor);
    DECLARE_ATTRIBUTE_CAPTUREDEF(Strength);

    FDamageStatics() {
        DEFINE_ATTRIBUTE_CAPTUREDEF(UAttributeSetBase, Armor, Target, false);
        DEFINE_ATTRIBUTE_CAPTUREDEF(UAttributeSetBase, Strength, Source, true);
    }
};

Performing the Math

Within Execute_Implementation, you use the ExecutionParams to attempt to query these captured attributes. Once you have the values, you can run any custom logic—conditional branching, clamping, or mathematical formulas—before finally using OutExecutionOutput to tell the GAS system how much to modify the target's attributes.

Because this logic runs on the server, it ensures that your game's damage formulas remain consistent and secure, even when dealing with complex interactions between multiple stats. By separating this math into a dedicated class, you keep your GameplayEffect assets clean while gaining the power of full C++ logic.

Key Takeaway: Execution Calculations are your bridge to complex, attribute-dependent logic, allowing you to use capture definitions to safely perform dynamic math before applying changes to an attribute.