[Unreal] GAS (1)

개요

언리얼 공식 사이트의 Gameplay Ability System에 대한 문서를 정리한 글이다.

GAS는 Actor들에게 어빌리티를 추가하거나 삭제하면서 기능변경을 구현할 수 있게 해준다. 

여기서 기능변경은 이펙트 변경, 스킬추가, 점프 등을 말한다.

구성요소

GAS를 활용하기 위해서 알아야하는 구성요소들을 간단하게 정리했다. 각각의 요소가 어떤 역할을 하는지는 따로 정리할 예정이다. 일단 어떤 것들이 있는지만 파악하자.

Gameplay Ability

<링크하기>

Ability Task

<링크 하기>

Gameplay Attributes

<링크 하기>

Gameplay Effects

<링크 하기>

Ability System Component

Actor가 GameplayAbility System과 상호작용하기 위해서는 Actor에 AbilitySystemComponent가 있어야 한다.

<링크 하기>

시스템 구성

GAS를 언리얼 프로젝트에서 사용하기 위한 절차이다.

Gameplay Ability 플러그인 추가

 

build.cs

다음 모듈들을 PublicDependencyModuleNames에 추가한다.

  • "GameplayAbilities"
  • "GameplayTags"
  • "GameplayTasks"

AbilitySystemComponent 

Actor에게 Gameplay Ability System을 사용하게 하기 위해서는 Ability System Component로 연결을 해줘야한다.

사용방법에는 2가지 Case가 있다.

  • Actor가 직접 Ability System Component 가지도록
  • PlayerState, PlayController가 Ability System Component를 가지도록

후자의 경우는 Actor가 파괴되거나  Respawn 되더라도 유지해야하는 정보가 있거나 쿨다운 정보등이 있을 경우 사용한다.

IAbilitySystemInterface 구현

Ability System을 사용하고자 하는 Actor에 IAbilitySystemInterface를 구현하게 해야한다.

#include "GameplayAbilities/Public/AbilitySystemInterface.h"

class MYPROJECT_API ADestinyPlayerController : public APlayerController, public IAbilitySystemInterface
{
	GENERATED_BODY()
}

 

Interface를 추가하면 GetAbilitySystemComponent()을 오버라이드 해야한다.

#include "GameplayAbilities/Public/AbilitySystemInterface.h"

class MYPROJECT_API ADestinyPlayerController : public APlayerController, public IAbilitySystemInterface
{
	GENERATED_BODY()
public:
    virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
}

그리고 AbilitySystemComponent를 참조할 UPROPERTY도 선언해준다.

#include "GameplayAbilities/Public/AbilitySystemInterface.h"

class MYPROJECT_API ADestinyPlayerController : public APlayerController, public IAbilitySystemInterface
{
	GENERATED_BODY()
public:
    UPROPERTY(VisibleDefaultOnly, BlueprintReadOnly, Category="Ability")
    UAbilitySystemComponent* AbilitySystemComp;

    virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
}

그리고 해당 Component를 반환하도록 GetAbilitySystemComponent()를 정의해주면 된다.

UAbilitySystemComponent* ADestinyPlayerController::GetAbilitySystemComponent() const
{
	return AbilitySystemComp;
}

문서 상에서는 자신에게 부착하는 장비나 신체 부위를 나타내는 엑터가 Gameplay Ability Systemp과 상호작용할 때 메인 엑터의 어빌리티 시스템을 이용해야할 수 있다고 한다. 이 때는 GetAbilitySystemComponent()가 메인 엑터의 component를 반환하도록 오버라이딩하면 된다고 한다.

++ 추가적으로 GAS는 여러 Actor가 하나의 GameplayAbilitySystemComponent를 공유할 수 있지만, 한 Actor가 여러 GameplayAbilitySystemComponent를 사용하는 것은 모호성을 유발하여 금지한다고 한다.

'Unreal' 카테고리의 다른 글

[Unreal] Replication && AttributeSet  (0) 2025.02.05
[Unreal] GAS - Gameplay Ability  (0) 2025.01.30
[Unreal] Lyra - Slot 구조  (0) 2025.01.28
[Unreal] Lyra - Animation Layer Interface  (0) 2025.01.27
[Unreal] Lyra - Anim Blueprint (1)  (1) 2025.01.26