Unreal Engine GAS(Gameplay Ability System) 심화LESSON 08
체력·마나·공격력·방어력 Attribute 구현
난이도심화
예상 시간155분
선수지식7강의 Attribute 분류
8강. 체력·마나·공격력·방어력 Attribute 구현
1. 이번 강의에서 해결할 문제
Attribute 선언을 누락하거나 RepNotify 함수 이름이 맞지 않으면 서버 값은 바뀌지만 Client HUD는 멈춥니다. Max 값보다 Current 값이 큰 초기 상태도 만들어질 수 있습니다. 선언, 접근자, 복제 알림과 초기화 Effect를 같은 계약으로 맞춥니다.
2. 학습 목표
3. 핵심 개념
AttributeSet은 값 정의와 경계 규칙을 소유합니다. 캐릭터 레벨별 기본값은 Instant Initialization Effect 또는 데이터 테이블로 적용할 수 있습니다. 이 과정은 명시적인 GE_InitializeAttributes Spec을 서버가 적용해 초기화와 Respawn 정책을 관찰하기 쉽게 만듭니다.
4. 구현
GASAttributeSet.h
#pragma once
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "GASAttributeSet.generated.h"
UCLASS()
class GASCOMBAT_API UGASAttributeSet final : public UAttributeSet
{
GENERATED_BODY()
public:
ATTRIBUTE_ACCESSORS(UGASAttributeSet, Health)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, MaxHealth)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, Mana)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, MaxMana)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, AttackPower)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, Defense)
ATTRIBUTE_ACCESSORS(UGASAttributeSet, IncomingDamage)
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_Health)
FGameplayAttributeData Health;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_MaxHealth)
FGameplayAttributeData MaxHealth;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_Mana)
FGameplayAttributeData Mana;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_MaxMana)
FGameplayAttributeData MaxMana;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_AttackPower)
FGameplayAttributeData AttackPower;
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_Defense)
FGameplayAttributeData Defense;
UPROPERTY(BlueprintReadOnly)
FGameplayAttributeData IncomingDamage;
UFUNCTION() void OnRep_Health(const FGameplayAttributeData& OldValue) const;
UFUNCTION() void OnRep_MaxHealth(const FGameplayAttributeData& OldValue) const;
UFUNCTION() void OnRep_Mana(const FGameplayAttributeData& OldValue) const;
UFUNCTION() void OnRep_MaxMana(const FGameplayAttributeData& OldValue) const;
UFUNCTION() void OnRep_AttackPower(const FGameplayAttributeData& OldValue) const;
UFUNCTION() void OnRep_Defense(const FGameplayAttributeData& OldValue) const;
};
서버 초기화 코드입니다.
GASCombatCharacter.cpp
void AGASCombatCharacter::ApplyInitialAttributes()
{
if (!HasAuthority() || !InitialAttributes || !AbilitySystemComponent) return;
FGameplayEffectContextHandle Context =
AbilitySystemComponent->MakeEffectContext();
Context.AddSourceObject(this);
FGameplayEffectSpecHandle Spec =
AbilitySystemComponent->MakeOutgoingSpec(
InitialAttributes, 1.0f, Context);
if (Spec.IsValid())
{
AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(*Spec.Data.Get());
}
}
5. 코드가 동작하는 이유
각 Replicated Attribute가 별도 OnRep를 가지므로 ASC Delegate가 예측·복제 변화의 이전 값을 받을 수 있습니다. Meta Attribute는 서버 계산 후 즉시 소비하므로 일반 상태처럼 복제하지 않습니다. 초기값도 Effect로 적용해 이후 레벨·장비 초기화와 같은 경로를 재사용합니다.
6. 실패 사례와 해결
7. 직접 실습
8. 이해 점검 질문 3개
9. 핵심 요약
MINI QUIZ
0 / 2체력·마나·공격력·방어력 Attribute 구현 미니 퀴즈
선택 즉시 정답과 해설을 확인할 수 있습니다. 결과는 이 브라우저에만 저장됩니다.
LESSON STATUS
8강. 체력·마나·공격력·방어력 Attribute 구현 미완료 상태학습을 마쳤나요?
직접 실습과 점검 질문까지 확인한 뒤 완료로 표시하세요.