Introduction to the GAS Plugin (Beginner) | Wood Dazhao - Viewing Notes

Words: 1157

Overview

Gameplay Ability System (GAS) is the framework in Unreal Engine for building complex ability systems. It provides a complete solution for handling abilities, effects, attributes, and state management in games. GAS is particularly well suited to games that require complex ability interactions, such as MOBAs, MMORPGs, and action games.

Core Concepts

Gameplay Tags

Gameplay Tags are the fundamental building blocks of GAS, used to identify various states and effects in the game. Compared with traditional booleans or enums, Tags have a hierarchical structure and support more flexible queries and matching.

Characteristics of Tags:

  • Hierarchical structure: supports parent-child relationships (e.g. State.Stun and State.Silence both inherit from State)
  • String-based: easy to configure and modify
  • Runtime management: can be modified without recompiling
  • Efficient queries: the engine optimizes Tag lookup performance

Use cases for Tags:

  • State identification (stun, silence, super armor, etc.)
  • Ability type classification
  • Effect immunity and interaction rules

Ability System Component (ASC)

The ASC is the core component of GAS and must be added to any Actor that needs to use the ability system.

Setup steps:

  1. Add module dependencies in the project’s .Build.cs file:
cpp
1
2
3
PublicDependencyModuleNames.AddRange(new string[] {
    "GameplayAbilities", "GameplayTags", "GameplayTasks"
});
  1. Add the ASC component and interface to your character class:
cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
UCLASS()
class YOUR_API AYourCharacter : public ACharacter, public IAbilitySystemInterface
{
    GENERATED_BODY()
    
public:
    AYourCharacter();
    
    // 实现AbilitySystem接口
    virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
    
    // ASC组件
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Abilities")
    UAbilitySystemComponent* AbilitySystemComponent;
    
protected:
    virtual void BeginPlay() override;
};
  1. Initialize the ASC and grant the initial abilities:
cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
void AYourCharacter::BeginPlay()
{
    Super::BeginPlay();
    
    if (AbilitySystemComponent) {
        for (auto& Ability : InitialAbilities) {
            if (Ability) {
                AbilitySystemComponent->GiveAbility(FGameplayAbilitySpec(Ability));
            }
        }
    }
}

Gameplay Ability (GA)

A Gameplay Ability represents a specific ability or action that a character can perform.

Ability lifecycle:

  1. CanActivate - checks whether the ability can be activated (cooldown, resources, conditions, etc.)
  2. Activate - activates the ability
  3. Commit - commits the cost (mana, stamina, etc.)
  4. Execute - executes the ability logic
  5. End - the ability ends

Example structure of an Ability Blueprint:

  graph TD
    A[Ability激活] --> B[播放蒙太奇动画]
    B --> C[等待命中事件]
    C --> D{是否命中目标?}
    D -->|是| E[应用Gameplay Effect]
    D -->|否| F[技能结束]
    E --> F

Gameplay Effect (GE)

Gameplay Effects are used to implement the concrete results of abilities, such as damage, healing, and state changes.

The three types of Effects:

  1. Instant - takes effect immediately (e.g. direct damage)
  2. Duration - lasts for a period of time (e.g. a damage-over-time buff)
  3. Infinite - lasts indefinitely and must be removed manually (e.g. a passive ability)

Configuration elements of an Effect:

  • Modifiers - attribute modifiers
  • Granted Tags - tags that are granted
  • Immunities - immunity rules
  • Stacking - stacking rules

Practical Examples

Implementing a Basic Attack Ability

1. Create the attack Ability

  • Configure the input binding (e.g. key 1)
  • Set blocking Tags to prevent ability spam
  • Add montage animation playback

2. Create the hit reaction Effect

  • Type: Duration (0.1-second hit stun)
  • Granted Tag: State.Hit
  • Configure hit reaction animation playback

3. Create the damage Effect

  • Type: Instant
  • Modifier: reduces the target’s health
  • Cost Effect: reduces your own stamina

Implementing a Block Ability

1. Block Ability configuration:

  graph LR
    A[按下格挡键] --> B[激活格挡Ability]
    B --> C[添加格挡Tag: State.Blocking]
    C --> D[播放格挡动画]
    D --> E[松开按键结束]
    E --> F[移除格挡Tag]

2. Damage immunity configuration: Configure Application Tag Requirements in the damage Effect:

  • Not State.Blocking - damage is only dealt when the target does not have the blocking Tag

Implementing a Combo System

Ability cancellation mechanism:

cpp
1
2
3
4
5
// 在Ability中配置取消Tags
CancelAbilitiesWithTag.AddTag("Ability.Positive");

// 在连招技能中配置被取消Tags
BlockAbilitiesWithTag.AddTag("Ability.Positive");

Advanced Features

Attribute System (Attribute Set)

Attribute Sets are used to define and manage a character’s various attributes.

Example attribute definition:

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
UCLASS()
class YOUR_API UYourAttributeSet : public UAttributeSet
{
    GENERATED_BODY()
    
public:
    UPROPERTY(BlueprintReadOnly, Category = "Attributes")
    FGameplayAttributeData Health;
    ATTRIBUTE_ACCESSORS(UYourAttributeSet, Health)
    
    UPROPERTY(BlueprintReadOnly, Category = "Attributes")  
    FGameplayAttributeData MaxHealth;
    ATTRIBUTE_ACCESSORS(UYourAttributeSet, MaxHealth)
    
    // 属性变化回调
    virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
    virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
};

Attribute modification flow:

  sequenceDiagram
    participant GE as Gameplay Effect
    participant AS as Attribute Set
    participant Character
    
    GE->>AS: 应用属性修改
    AS->>AS: PreAttributeChange (验证)
    AS->>AS: 实际修改属性值
    AS->>Character: PostGameplayEffectExecute (通知)
    Character->>Character: 更新UI/状态

Ability Prediction

GAS supports client-side prediction, providing a smoother networked experience:

Features that support prediction:

  • Ability activation
  • Attribute modification
  • Gameplay Cues (visual effects, sound effects)
  • Montage playback

Effect Stacking

Stacking configuration options:

  • Stacking type: stack by source or stack by target
  • Stack limit: maximum number of stacks
  • Overflow handling: reject the new stack or refresh the duration
  • Expiration policy: expire stack by stack or expire all at once

Best Practices

Project Planning Advice

1. Tag system design

  • Plan the Tag hierarchy in advance
  • Establish a unified naming convention
  • Use the Tag editor for visual management

2. Ability organization

  • Divide Abilities into categories by function (attack, defense, movement, etc.)
  • Create a base Ability parent class to reduce duplicated code
  • Use DataTables to configure ability values

3. Performance optimization

  • Avoid executing complex logic in Tick
  • Use prediction judiciously
  • Keep an eye on the amount of network-synchronized data

Development Workflow

Designer-programmer collaboration:

  • Designers: configure Tags, Effects, and animation montages
  • Programmers: implement complex Ability logic and custom Task nodes
  • Artists: provide animation assets and visual effects

Configuration-driven development:

  graph TB
    A[策划配置Tags和Effects] --> B[程序实现Ability逻辑]
    B --> C[美术提供资源]
    C --> D[整合测试]
    D --> E[迭代优化]

Debugging and Troubleshooting

Common Debugging Techniques

1. Checking Tag state

cpp
1
2
3
4
5
// 在控制台显示当前Tags
ShowDebug AbilitySystem

// 查看特定Ability的状态
AbilitySystem.DebugAbility <AbilityName>

2. Effect debugging

cpp
1
2
3
4
5
// 显示当前激活的Effects
AbilitySystem.DebugEffect

// 查看属性修改历史
AbilitySystem.DebugAttribute

Solving Common Problems

An ability cannot be activated:

  • Check the cooldown and cost configuration
  • Verify the Blocking Tags settings
  • Confirm network authority (server-side abilities)

An effect does not take effect:

  • Check the Tag Requirements configuration
  • Verify the Immunity settings
  • Confirm that the Attribute Set is configured correctly

Learning Resources

Official Documentation

Sample Projects

  • Action RPG - single-player GAS sample
  • Shooter Game - sample that includes network synchronization

Community Resources

  • The GAS section of the Unreal Engine forums
  • Related technical blogs and video tutorials

Conclusion

GAS provides a powerful and flexible framework for ability systems. With sensible planning and design, it can greatly improve the efficiency and quality of game development. Mastering GAS requires understanding its core concepts and design philosophy, and customizing and extending it appropriately for the needs of your actual project.

Key takeaways:

  • Tags are the cornerstone of the system, and good Tag design is essential
  • Understand the Ability lifecycle and its interaction mechanisms
  • Use prediction judiciously to improve the networked game experience
  • Establish workflows and conventions that suit your team

By studying this guide, you should be able to understand the core concepts of GAS and start using this powerful framework in real projects.

Reference Information

This post contains some AI-assisted content, reviewed and edited by the author before publishing.
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...