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

Defining Attribute Sets for Character Stats

Create a custom AttributeSet class and define gameplay attributes using the macro system to register them with the Ability System Component.

In this lesson, you will learn how to structure your character’s numerical data, such as Health and Stamina, into a formal UAttributeSet class that the Gameplay Ability System (GAS) can track and manipulate.

The Role of Attribute Sets

In GAS, an AttributeSet acts as a centralized container for all numeric variables that affect gameplay. While you could store variables directly in your Character class, placing them in an AttributeSet allows the Ability System Component (ASC) to automatically handle features like networking replication, clamping, and attribute modifiers (buffs/debuffs) provided by Gameplay Effects.

Defining Attributes

To define an attribute, you must use the GAMEPLAYATTRIBUTE_PROPERTY_GETTER and GAMEPLAYATTRIBUTE_VALUE macros. This allows GAS to perform "magic" behind the scenes, such as tracking internal base values versus current values modified by effects.

Here is how you define a basic Health attribute in your header file:

#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "MyAttributeSet.generated.h"

UCLASS()
class MYPROJECT_API UMyAttributeSet : public UAttributeSet
{
    GENERATED_BODY()

public:
    // Define the Health attribute
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
    FGameplayAttributeData Health;

    // Macro to register the attribute for the ASC
    GAMEPLAYATTRIBUTE_PROPERTY_GETTER(UMyAttributeSet, Health);
    GAMEPLAYATTRIBUTE_VALUE_GETTER(Health);
    GAMEPLAYATTRIBUTE_VALUE_SETTER(Health);
    GAMEPLAYATTRIBUTE_VALUE_INITTER(Health);
};

Why use Macros?

The macros are non-negotiable because they provide the getter and setter logic required by the UAbilitySystemComponent. When you call GetHealth() or SetHealth(), you aren't just accessing a float; you are interacting with the GAS internal system. This ensures that whenever you modify the value—such as taking damage—the Ability System can broadcast the change to any listening UI elements or passive effects.

Once defined, you simply instantiate this class within your Character’s AbilitySystemComponent during initialization. By encapsulating stats here, you decouple your character's logic from the specific math of combat, allowing effects to modify these values safely without directly touching character code.

Key Takeaway: Use the FGameplayAttributeData type and the associated GAS macros to wrap your character’s stats, enabling the Ability System to manage value replication and effect-based modifiers automatically.