Overview
This article introduces the usage of gameplay effect context in the Gameplay Ability System and how to customize context data.
Gameplay Effects
According to the GAS Documentation, Gameplay Effect Context is a special structure in GAS used to pass relevant context data in various application processes of GAS (MMC/Execution, AttributeSets, and GameplayCues),
At the same time, it can also be customized through C++ to add custom data.
Since customizing gameplay effect context requires mandatory use of C++, it brings many inconveniences for blueprint developers when utilizing GAS to implement advanced features!
Therefore, GGA provides a better solution, which is gameplay effect context payload system。
Context Payload System
GGA provides a custom gameplay effect context structure:GGA_GameplayEffectContext, which internally contains an array of InstancedStruct, allowing you to add, read, and remove context payload by struct type.
At the same time, GGA provides a simple API to get context payload or modify it through blueprints or C++.
The following image shows an example of using these APIs:
Note
To use the context payload system, you need to selectGGA_AbilitySystemGlobals in Project Settings -> GameplayAbilitiesSettings -> AbilitySystemGlobalsClass.
Before use, configure GGA_AbilitySystemGlobals as described in Initial Setup so GAS allocates GGA's context type. There is one entry per struct type: adding the same type again replaces its previous value. Payload transport is subject to context serialization and data-type limits, so include only the data you need.
Best Practices
You can use suitable Blueprint or C++ structs as payload. For network transport, the struct and its fields must support the relevant network serialization; verify the result in your actual multiplayer scenario.
At the same time, I recommend naming your context payload structure types in the form of ContextPayload_XXX.
In my combat system, I use FGCS_ContextPayload_Combat to store all context data related to combat.