언리얼 엔진의 게임플레이 어빌리티 시스템을 위한 게임플레이 어트리뷰트 및 어트리뷰트 세트
게임플레이 어트리뷰트 및 어트리뷰트 세트 사용하기
dev.epicgames.com
https://github.com/tranek/GASDocumentation?tab=readme-ov-file#concepts-a
GitHub - tranek/GASDocumentation: My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer s
My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer sample project. - tranek/GASDocumentation
github.com
- FGameplayAttribute를 사용해 Gameplay 관련 소수값을 저장/계산 수정하는 기능
- 남은 생명력
- Vehicle의 최고 속력
- 아이템의 사용 가능 횟수
- GAS의 Actor는 Gameplay Attribute(이하 GA)는 Attribute Set(이하 AS)에 저장한다.
- 이는 Attribute를 Actor의 ASC에 등록하고, GA와 시스템의 나머지 부분간의 상호작용 관리에 유리하다.
- 상호작용에는 범위 제한, 일시적 값 변경을 위한 계산, 영구적 값 변경을 하는 이벤트에 대한 반응이 있다.
- GA는 Gameplay Effect로만 수정되어야 한다.
- 그래야 ASC가 변화를 예측할 수 있다.
Gameplay Attribute
- 생성하려면 우선 Attribute Set을 만들어야 한다.
- 경우에 따라서는 AS가 없이도 GA가 존재할 수 있다.
- 보통은 적절한 GA Type을 포함하는 AS가 없는 ASC에 GA가 저장된 경우
- 하지만 이 케이스는 GA가 ASC와 상호작용하는 그 어떠한 행동도 정의되지 않고 값만 저장한다.
- 때문에 권장되지 않는 방식이다.
- 만약 GA를 Editor에 노출하고 싶지 않다면, UPROPERTY 지정자에 Meta=(HideInDetailsView)를 추가하면 된다.
- GA 값은 CurrentValue와 BaseValue로 구분된다.
CurrentValue
- BaseValue에 더불어 Gameplay Effects로 발생한 일시적인 변화를 합친 값
- Duration, Infinite Gameplay Effects에 의해 값이 변경된다.
- Duration Gameplay Effects: 미리 지정된 시간 동안만 효과가 적용되는 Gameplay Effects
- Infinite Gameplay Effects: 특정 조건을 만족하기 전까지 계속 효과가 유지되는 Gameplay Effects
- PreAttributeChange() 함수에서 CurrentValue 값의 Clamping 작업을 적용할 수 있다.
BaseValue
- Attribute의 영구적인 값
- Instant 혹은 Periodic Gameplay Effects에 의해 값이 변경된다.
- Instant Gameplay Effects: 즉시 발동되지만 그 효과가 영구적인 Gameplay Effects
- Periodic Gameplay Effects: 주기적으로 반복해서 효과가 발동하는 Gameplay Effects
- 간혹 BaseValue Attribute의 최대값하고 혼동하지만 이는 잘못된 사용법이다.
- 현재는 Attribute의 최대값은 별도의 Attribute로 분리되어야 한다.
- FAttributeMetaData에 Min/Max Value Column이 있지만, Epic에서 WIP라고 코멘트 해두었다.
- PostGameplayEffectExecute()에서 BaseValue 값의 Clamp를 적용할 수 있다.
Meta Attributes
- Attributes들과 상호작용을 목적으로 일시적인 값을 담고 있는 임시 Attribute를 지칭
- 예를 들어 damage의 경우, GameplayEffect로 health Attribute에 직접 영향을 주는 대신
damage라는 Meta Attribute를 임시선언으로 사용할 수 있다. - 이 때 Meta Attribute는 health Attribute에 도달하기 전에 여러 변화를 가할 수 있다.
- GameplayEffectExecutionCalculation 함수를 통해 Buff/Debuff 적용
- Shield Attribute에 의해 발생하는 damage의 감소
- 예를 들어 damage의 경우, GameplayEffect로 health Attribute에 직접 영향을 주는 대신
- Meta Attribute는 Gameplay Effect간의 영속성이 없고 모두에 의해 override될 수 있다.
- 또한 일반적으로 Replicate 되지 않는다.
- Meta Attribute는 적용 대상 Attribute의 수치 변화와 그에 따른 상호작용을 논리적으로 분리할 수 있다.
- Gameplay Effect가 "얼마나 수치를 변경할 것인가?"를 결정한다면,
Attribute Set은 "수치가 바뀐 뒤 어떻게 반응할 것인가?"를 결정한다. - 하지만 상위 Attribute Set에서 제공하는 Attribute를 대상으로 한다 해도,
하위 Attribute Set의 구성에 따라 실제 변화량과 그 반응은 다를 수 있다. - Meta Attribute는 이렇게 다양한 경우에 대해 유연하게 대응할 수 있다.
- Gameplay Effect가 "얼마나 수치를 변경할 것인가?"를 결정한다면,
- 물론 Meta Attribute는 좋은 패턴이지만 필수적인 것은 아니다.
- 만약 Attribute에 대해 하나의 ExecutionCalculation만 제공되고 모든 Actor가 그 Attribute Set을 사용한다면,
관련된 값들을 직접 수정하는 방식으로 작업하는 것이 더 좋을 수 있다.
- 만약 Attribute에 대해 하나의 ExecutionCalculation만 제공되고 모든 Actor가 그 Attribute Set을 사용한다면,
Responding to Attribute Changes
- Attribute의 변화를 UI나 다른 Gameplay에 전달하려면,
UAbilitySystemComponent::GetGameplayAttributeValueChangeDelegate(FGameplayAttribute Attribute)를 쓴다. -
더보기
typedef TMulticastDelegate_OneParam< void, const FOnAttributeChangeData & > FOnGameplayAttributeValueChange FOnGameplayAttributeValueChange & GetGameplayAttributeValueChangeDelegate ( FGameplayAttribute Attribute )
AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(AttributeSetBase->GetHealthAttribute()).AddUObject(this, &AGDPlayerState::HealthChanged); virtual void HealthChanged(const FOnAttributeChangeData& Data);
- 이 때 Attribute 변수는 Server에서만 값이 채워진다.
- BP에서는 이 함수가 AsyncTask로 감싸져서 제공된다.
- 보통 UI_HUD에서 사용되며 해당 Widget의 Destruct Event에서 EndTask()가 호출되기 전까지 죽지 않는다.
Derived Attributes
- 하나의 Attribute가 복수의 Attribute로부터 값이 정해질 때, Infinite Gameplay Effect를 여러 개의 Modifier Magnitude Calculation(이하 MMC)와 함께 사용한다.
- Derived Attributes는 해당 Attribute에 의존성을 갖는 Attribute들을 자동으로 갱신해준다.
- Derived Attribute의 연산자 공식은 Modifier Aggregator와 동일한 방식으로 동작한다.
- 만약 저해진 순서대로 계산이 되어야 한다면, MMC 내부에서 시행하면 된다.
- PIE에서 Multi Client로 실행한 경우, Editor Preferences -> Run Under One Process 옵션을 비활성화 해야한다.
- 안 그러면 Derived Attributes가 각각의 Attribute가 client에서 첫번째로 update되지 않으면 갱신하지 않을 것이다.
예시
- 다음과 같이 값이 정해지는 TestAttrA가 있다고 가정하자.
- TestAttrA = (TestAttrA + TestAttrB) * (2 * TestAttrC) .
- 이 때 TestAttrA에 대한 Derived Attributes 설정은 다음과 같다.
'UE5 > GAS' 카테고리의 다른 글
[GAS] Ability Task (0) | 2024.05.16 |
---|---|
[GAS] Gameplay Effect (0) | 2024.05.15 |
[GAS] Attribute Set (1) | 2024.05.14 |
[GAS] Ability System Component (0) | 2024.05.13 |
[GAS] Gameplay Ability System 소개 (0) | 2024.05.10 |