1일1알

Gameplay Abilities (GA) 본문

언리얼/Gameplay Ability System

Gameplay Abilities (GA)

영춘권의달인 2024. 6. 16. 19:15

Gameplay Abilities (GA)

GA는 액터가 게임에서 할 수 있는 모든 행동 또는 스킬을 뜻한다. 점프나 공격같은 행동들을 GA로 만들 수 있다.

ASC에 등록하여 발동시킬 수 있다.

 

GA의 발동 과정

출처 : https://github.com/tranek/GASDocumentation

 

ASC의 GiveAbility 함수를 통해 ASC에 GA를 등록하고 TryActivateAbility함수를 통해 ASC에 등록된 GA를 발동시킬 수 있다.

GiveAbility 를 통해 GA정보를 넘길때는 클래스정보를 바로 넘기는 것이 아닌 GameplayAbilitySpec이라고 하는 GAS에서 제공하는 어빌리티에 대한 정보를 넘겨주도록 되어있다.

 

  • Gameplay Ability Spec (스펙) : GA에 대한 정보를 담고 있는 구초제, ASC는 직접 어빌리티를 참조하지 않고 스펙 정보를 가지고 있는다. 스펙은 어빌리티의 현재 상태와 같은 다양한 정보를 가지고 있다. ASC로부터 어빌리티를 다룰때는 스펙에 있는 Handle을 사용해 컨트롤한다. 간단하게 GA의 정보는 스펙이고, GA의 인스턴스에 대한 레퍼런스는 스펙 핸들이다.

 

GA의 정보를 이용해 스펙을 만들어서 GiveAbility 에 넘겨주면 넘겨받은 ASC는 해당 GA를 발동시킬 수 있다.

스펙에는 InputID값을 지정할 수 있고  EnhancedInputComponent에 함수를 바인딩할때 인자로 InputID를 넘겨줘서 들어온 입력에 알맞은 어빌리티를 발동시킬 수 있다.

 

  • FindAbilitySpecFromInputId함수를 사용해 ASC에 등록된 스펙을 검사해 입력에 매핑된 GA를 찾을 수 있다. 사용자 입력이 들어오면  ASC에서 입력에 관련된 GA를 검사한다. GA를 찾으면 현재 발동 중인지를 판별한다. (IsActive) 
    • AbilitySpecInputPressed : GA가 이미 발동중이면 입력이 왔다는 신호를 전달한다.
    • TryActivateAbility : GA가 발동하지 않았다면 새롭게 발동시킨다.
  • 입력이 떨어지면 AbilitySpecInputReleased를 통해 입력이 떨어졌다는 신호를 전달한다.

 

ASC의 FindAbilitySpecFromClass(ClassName::StaticClass()); 함수를 통해 ASC에 있는 해당 GA의 스펙 정보를 가져올 수 있다.  TryActivateAbility()함수에 가져온 스펙 정보의 핸들을 넣어서 GA를 발동시킬 수 있다.

 

게임플레이 어빌리티를 내부에서 취소하려면 CancelAbility()를 호출한다. 그러면 EndAbility()가 호출되고 해당 WasCancelled 파라미터가 true로 설정된다.

 

어빌리티를 외부에서 취소하기 위한 함수들도 있다.

/** Cancels the specified ability CDO. */
void CancelAbility(UGameplayAbility* Ability);	

/** Cancels the ability indicated by passed in spec handle. If handle is not found among reactivated abilities nothing happens. */
void CancelAbilityHandle(const FGameplayAbilitySpecHandle& AbilityHandle);

/** Cancel all abilities with the specified tags. Will not cancel the Ignore instance */
void CancelAbilities(const FGameplayTagContainer* WithTags=nullptr, const FGameplayTagContainer* WithoutTags=nullptr, UGameplayAbility* Ignore=nullptr);

/** Cancels all abilities regardless of tags. Will not cancel the ignore instance */
void CancelAllAbilities(UGameplayAbility* Ignore=nullptr);

/** Cancels all abilities and kills any remaining instanced abilities */
virtual void DestroyActiveState();

 

GA의 주요 함수에는 4가지가 있다.

  • CanActivateAbility : 어빌리티가 발동될 수 있는지 파악한다.
  • ActivateAbility : 어빌리티가 발동될 때 호출한다.
  • CancelAbility : 어빌리티가 취소될 때 호출된다.
  • EndAbility : 스스로 어빌리티를 마무리할 때 호출된다.

ASC의 OwnerActor에서 해당 액터가 처음부터 보유하고 있는 어빌리티들을 관리해야 하는데, GA들은 전부 GameplayAbility 클래스를 상속받고 있기 때문에 클래스 정보를 뜻하는 TSubclassOf<GameplayAbility>를 상황에 맞는 자료구조로 관리하고 해당 액터의 블루프린트 클래스에서 알맞은 GA를 넣어주는 방법을 생각해볼 수 있다.

 

GA의 인스턴싱 정책은 3가지가 있다. 이것은 GA 활성화시 GA의 인스턴스화 여부와 방법을 결정한다.

  • Instanced Per Actor : 각 ASC에는 활성화될때 재사용되는 GA 인스턴스가 하나만 존재한다. (주로 이 옵션을 사용)
  • Instanced Per Execution : GA가 활성화될 때마다 새로운 인스턴스가 생성된다.
  • Non-Instanced : CDO(Class Default Object)에서 작동하고 인스턴스가 생성되지 않는다.

'언리얼 > Gameplay Ability System' 카테고리의 다른 글

Attribute  (0) 2024.07.02
Ability Task (AT)  (0) 2024.06.17
Gameplay Tags  (0) 2024.06.16
Ability System Component (ASC)  (0) 2024.06.16
GAS (Gameplay Ability System) 개요  (1) 2024.06.16