GameplayEffect, GameplayEffectReplicationMode, AbilitySystemComponent, AttributeSet

김지윤·2025년 5월 2일
0

UE5_GAS

목록 보기
1/22
  1. GameplayEffect
  • 변경할 Attribute 및 GameplayTag만 갖고 있는 DataOnly 클래스

  • Modifiers와 Executions를 통해 대상의 Attribute 값을 즉시 또는 일정 시간 동안 변경

  • GameplayTag를 추가/제거하여 버프/디버프를 관리

  • GameplayEffectSpec을 통해 여러 곳에서 같은 효과로 적용 가능

  • GameplayEffectContext를 통해 GameplayEffect가 어떻게 적용되었는지 확인 가능, 어떤 속성의 데미지인지, 누가 때렸는지, 누가 맞았는지 등등.. 로그 같은 개념

  1. GameplayEffectReplicationMode
  • GameplayEffect를 얼마나 Replicate할 것인지 결정하는 enum

  • Full - 모든 데이터를 복제함

  • Mixed - Mixed보단 Auto라고 생각하면 편하다. Owner 및 Autonomous Proxy에는 Full, Simulation Proxy에는 Minimal로 할당한다. (Autonomouse Proxy는 로컬에서 조작하지만 권한은 없는 객체, Simulation Proxy는 다른 기기에 의해 조작되는 객체를 말한다.)

  • Minimal - GameplayTags, GameplayCues 정보만 복제, GameplayEffectSpec 데이터는 서버에만 존재

  • 해당 설정을 해두면 언리얼이 자동으로 네트워크 최적화를 해준다

  1. AbilitySystemComponent
  • Owner Actor - 컴포넌트 소지 액터

  • Avatar Actor - 컴포넌트에 의해 조작되는 액터

  • 다른 캐릭터들의 경우 Owner Actor == Avatar Actor. 둘 다 폰(캐릭터)다. 내 캐릭터의 경우 Owner Actor는 PlayerState, Avatar Actor는 캐릭터다. 리스폰 시에도 유지되어야 하는 정보가 있기 때문에 이런 식으로 설계한다.

  • 이 컴포넌트를 가진 객체가 이 컴포넌트의 GameplayEffectReplicationMode를 정한다.

  1. AttributeSet
  • 게임 플레이에 필요한 캐릭터의 정보(HP, Level 등)을 갖고 있는 객체

  • float이나 int등의 자료형 대신 FGameplayAttributeData라는 이름의 구조체 변수를 사용

  • 해당 구조체 사용 시 클라이언트 예측 등의 네트워크 관련 기술이 자동으로 적용됨

// AttributeSet.h
// Getter, Setter, Initter를 자동 생성해주는 매크로를 호출하기 위해 정의하는 구문
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
	GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
	GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
	GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
	GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
    	
// 일반적인 자료형 대신 FGameplayAttributeData를 사용할 경우, 클라이언트 예측 등의 네트워크 로직이 자동으로 적용됨
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Vital Attributes")
FGameplayAttributeData Health;
// define을 통해 Getter, Setter, Initter 자동 생성
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Health);

// Health 변경사항 콜백 함수
UFUNCTION()
void OnRep_Health(const FGameplayAttributeData& OldHealth) const;

// AttributeSet.cpp
void UAuraAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth) const
{
	// GAS 후처리 흐름을 자동으로 실행하는 매크로, 클라이언트 예측 등의 로직이 여기에 포함
	GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, Health, OldHealth);
}
    
profile
공부한 거 시간 날 때 작성하는 곳

0개의 댓글