Unreal Engine GAS(Gameplay Ability System) 심화LESSON 09
PreAttributeChange와 PostGameplayEffectExecute
난이도심화
예상 시간145분
선수지식8강의 전투 AttributeSet
9강. PreAttributeChange와 PostGameplayEffectExecute
1. 이번 강의에서 해결할 문제
모든 Clamp와 데미지 처리를 한 함수에 넣으면 임시 Modifier 변화와 Instant Effect 실행을 구분하지 못합니다. MaxHealth가 바뀔 때 Health 비율을 유지할지, Damage를 언제 0으로 비울지도 불명확해집니다.
2. 학습 목표
3. 핵심 개념
PreAttributeChange는 Current 값이 바뀌기 직전의 값 조정에 적합하지만 영구 규칙의 유일한 방어선은 아닙니다. PostGameplayEffectExecute는 Instant·Periodic Effect 실행 결과를 처리해 Meta Damage를 Health로 옮기고 사망 이벤트를 발생시키는 곳에 적합합니다.
4. 구현
GASAttributeSet.cpp
void UGASAttributeSet::PreAttributeChange(
const FGameplayAttribute& Attribute,
float& NewValue)
{
Super::PreAttributeChange(Attribute, NewValue);
if (Attribute == GetHealthAttribute())
NewValue = FMath::Clamp(NewValue, 0.0f, GetMaxHealth());
else if (Attribute == GetManaAttribute())
NewValue = FMath::Clamp(NewValue, 0.0f, GetMaxMana());
}
void UGASAttributeSet::PostGameplayEffectExecute(
const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
if (Data.EvaluatedData.Attribute == GetIncomingDamageAttribute())
{
const float Damage = FMath::Max(0.0f, GetIncomingDamage());
SetIncomingDamage(0.0f);
if (Damage > 0.0f)
{
SetHealth(FMath::Clamp(
GetHealth() - Damage, 0.0f, GetMaxHealth()));
HandleDamageResult(Data, Damage);
}
}
else if (Data.EvaluatedData.Attribute == GetHealthAttribute())
{
SetHealth(FMath::Clamp(GetHealth(), 0.0f, GetMaxHealth()));
}
}
HandleDamageResult는 Source ASC, Effect Causer와 HitResult를 Context에서 읽고 Target Avatar의 전투 인터페이스 또는 Delegate에 결과를 전달합니다. AttributeSet이 특정 Character 클래스를 직접 Cast하지 않게 합니다.
5. 코드가 동작하는 이유
Meta Damage를 먼저 비우고 Health에 적용하면 다음 Effect가 이전 Damage를 재사용하지 않습니다. 최종 Health를 다시 Clamp해 Modifier 경로 밖의 Instant 결과도 범위 안에 둡니다. Context를 전달하면 Kill Credit과 피격 방향을 계산 계층 밖에서도 사용할 수 있습니다.
6. 실패 사례와 해결
7. 직접 실습
8. 이해 점검 질문 3개
9. 핵심 요약
MINI QUIZ
0 / 2PreAttributeChange와 PostGameplayEffectExecute 미니 퀴즈
선택 즉시 정답과 해설을 확인할 수 있습니다. 결과는 이 브라우저에만 저장됩니다.
LESSON STATUS
9강. PreAttributeChange와 PostGameplayEffectExecute 미완료 상태학습을 마쳤나요?
직접 실습과 점검 질문까지 확인한 뒤 완료로 표시하세요.