SGG Devlog

June 2024

Worked on Gameplay Ability System

  ·   5 min read

Integrating the Gameplay Ability System in Unreal Engine 5: A Guide to Etrelia’s Attribute Set

Introduction

In Etrelia, players will have the chance to develop their own unique characters based on a D100 system of the now classic attributes: Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma. These foundational attributes serve as the bedrock of character development, shaping each player’s journey and interactions within the game world. However, Etrelia also introduces several unique attributes that add depth and complexity to gameplay. Among these, Magic Power and the characters’ age play pivotal roles, influencing not only combat effectiveness but also interactions with the environment and other characters.

The Gameplay Ability System (GAS) in Unreal Engine 5 offers the best tools to manage these complex interactions. GAS excels at handling the intricate dynamics between attributes, effects from items or skills, and the various statuses that characters can have. By leveraging GAS, we can create a rich, dynamic gameplay experience where every decision and action has meaningful consequences.

In this article, we will explore how the different pieces of GAS fit together to achieve this sophisticated system in Etrelia. We will delve into the setup and implementation of GAS in C++, detailing the process of creating and managing the attribute set. By the end of this guide, you will have a comprehensive understanding of how to integrate GAS into your own Unreal Engine 5 projects, enhancing the depth and engagement of your game.

Understanding the Gameplay Ability System

The Gameplay Ability System (GAS) is a powerful framework in Unreal Engine 5 designed to handle complex gameplay mechanics and interactions. It provides a flexible and efficient way to implement abilities, manage character attributes, and handle various gameplay effects.

What is the Gameplay Ability System?

GAS allows developers to define and manage abilities and attributes for characters in a flexible manner, supporting complex and dynamic interactions ideal for RPGs and action games.

Key Benefits of Using GAS

  1. Flexibility: Easily customizable to fit unique game needs.
  2. Efficiency: Streamlines ability and attribute implementation, reducing custom code.
  3. Scalability: Handles large, complex systems with many abilities and attributes.
  4. Integration: Seamlessly integrates with other Unreal Engine systems like animation, AI, and networking.

How GAS Works

GAS is composed of key components:

  1. Ability System Component (ASC): Manages ability execution and gameplay effects.
  2. Gameplay Abilities: Modular gameplay logic for actions like spells or attacks.
  3. Attribute Sets: Collections of character stats like Health, Mana, and Strength.
  4. Gameplay Effects: Define changes to attributes or game state, such as damage or buffs.
  5. Gameplay Tags: Control interactions between abilities and effects.

By using these components, GAS provides a comprehensive framework for implementing and managing complex gameplay mechanics, enabling rich and engaging gameplay experiences.

For more detailed information, refer to the official documentation.

In the next sections, we will guide you through setting up GAS in your Unreal Engine 5 project, creating base classes, and implementing abilities and attribute sets. This practical approach will help you effectively use GAS to enhance your game development process.

Setting Up GAS in Unreal Engine 5

Setting Up GAS in Unreal Engine 5

Integrating the Gameplay Ability System (GAS) into your Unreal Engine 5 project involves several key steps. This section will guide you through the process of setting up GAS, including project setup, creating the necessary base classes, and integrating GAS components into your game.

Project Setup

  1. Create or Open Your Project:

    • Open Unreal Engine 5 and create a new project or open an existing one.
  2. Enable Required Plugins:

    • Navigate to the Edit menu and select Plugins.
    • Search for and enable the following plugins:
      • GameplayAbilities
      • GameplayTags
      • GameplayTasks
    • Restart the editor to apply the changes.

Creating Base Classes

To effectively use GAS, you need to create several base classes that will handle abilities, attributes, and the ability system component. Refer to this documentation that is the best on the topic that I could find.

  1. Create a Custom Ability System Component:

    • This component will manage abilities and gameplay effects for your characters.
    // MyGameAbilitySystemComponent.h
    #pragma once
    
    #include "CoreMinimal.h"
    #include "AbilitySystemComponent.h"
    #include "MyGameAbilitySystemComponent.generated.h"
    
    UCLASS()
    class MYGAME_API UMyGameAbilitySystemComponent : public UAbilitySystemComponent
    {
        GENERATED_BODY()
    };
    
    1. Create a Custom Attribute Set:

      • Define custom attributes for your game by creating a new attribute set class. Do not forget the accessor macros.
      // MyGameAttributeSet.h
      #pragma once
      
      #define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
       GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
       GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
       GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
       GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
      
      #include "CoreMinimal.h"
      #include "AttributeSet.h"
      #include "AbilitySystemComponent.h"
      #include "MyGameAttributeSet.generated.h"
      
      UCLASS()
      class MYGAME_API UMyGameAttributeSet : public UAttributeSet
      {
          GENERATED_BODY()
      
      public:
          UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes")
          FGameplayAttributeData Health;
          ATTRIBUTE_ACCESSORS(UGDAttributeSetBase, Health)
      
          UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes")
          FGameplayAttributeData Mana;
          ATTRIBUTE_ACCESSORS(UGDAttributeSetBase, Health)
      
          UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Attributes")
          FGameplayAttributeData Strength;
          ATTRIBUTE_ACCESSORS(UGDAttributeSetBase, Health)
      
          // Additional attributes go here
      };
      
  2. Integrate GAS into Your Character Class:

    • Add the ability system component and attribute set to your character class by plugging it to the constructor.
    // MyGameCharacter.h
    #pragma once
    
    #include "CoreMinimal.h"
    #include "GameFramework/Character.h"
    #include "MyGameAbilitySystemComponent.h"
    #include "MyGameAttributeSet.h"
    #include "MyGameCharacter.generated.h"
    
    UCLASS()
    class MYGAME_API AMyGameCharacter : public ACharacter
    {
        GENERATED_BODY()
    
    public:
        AMyGameCharacter();
    
    protected:
        virtual void BeginPlay() override;
    
    public:
        virtual void Tick(float DeltaTime) override;
    
        virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    
        UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Abilities")
        UMyGameAbilitySystemComponent* AbilitySystemComponent;
    
        UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Attributes")
        UMyGameAttributeSet* AttributeSet;
    };
    
    // MyGameCharacter.cpp
    #include "MyGameCharacter.h"
    
    AMyGameCharacter::AMyGameCharacter()
    {
        // Set this character to call Tick() every frame.
        PrimaryActorTick.bCanEverTick = true;
    
        // Create the ability system component.
        AbilitySystemComponent = CreateDefaultSubobject<UMyGameAbilitySystemComponent>(TEXT("AbilitySystemComponent"));
    
        // Create the attribute set.
        AttributeSet = CreateDefaultSubobject<UMyGameAttributeSet>(TEXT("AttributeSet"));
    }
    
    void AMyGameCharacter::BeginPlay()
    {
        Super::BeginPlay();
    }
    
    void AMyGameCharacter::Tick(float DeltaTime)
    {
        Super::Tick(DeltaTime);
    }
    
    void AMyGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
    {
        Super::SetupPlayerInputComponent(PlayerInputComponent);
    
        // Bind ability activation input here.
    }
    

Conclusion

Setting up GAS in Unreal Engine 5 involves creating custom components and classes to manage abilities and attributes. By following these steps, you can integrate a robust ability system into your game, enhancing the depth and complexity of your gameplay mechanics. For more detailed information, refer to the official GAS documentation.

I will cover the implementation of custom abilities in further articles, stay tuned!

Additional Resources