이번 포스트에서는 Attribute를 초기화하는 2가지 방법 중에서 2번째 방법인
Gameplay Effect를 통해 Attribute를 초기화하는 방법을 알아보겠습니다.
우선, 이전에 설정한 Data Table은 삭제하는 것으로 시작하겠습니다.
1) AuraCharacterBase
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AbilitySystemInterface.h"
#include "AuraCharacterBase.generated.h"
class USkeletalMeshComponent;
class UAbilitySystemComponent;
class UAttributeSet;
class UGameplayEffect;
UCLASS(Abstract)
class AURA_API AAuraCharacterBase : public ACharacter, public IAbilitySystemInterface
{
.
.
.
/*
* GAS Section
*/
.
.
.
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Attributes")
TSubclassOf<UGameplayEffect> DefaultPrimaryAttributes;
protected:
/*
* Attribute Section
*/
void InitializePrimaryAttribute() const;
};
.
.
.
void AAuraCharacterBase::InitializePrimaryAttribute() const
{
check(IsValid(GetAbilitySystemComponent()));
check(DefaultPrimaryAttributes);
const FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(
DefaultPrimaryAttributes,
1.0f,
ContextHandle
);
GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*(SpecHandle.Data.Get()), GetAbilitySystemComponent());
}
현재 진행중인 프로젝트에 존재하는 모든 캐릭터들의 조상인 AuraCharacterBase에
Attribute를 초기화하는 용도의 GameplayEffect인 DefaultPrimaryAttributes를 추가하고
이를 토대로 Attribute를 초기화하는 함수 InitializePrimaryAttribute를 추가하였습니다.
InitializePrimaryAttribute 함수의 경우, 다음과 같이 동작합니다.
우선 ASC와 GE가 존재하는지 확인합니다.
그 후 GE의 유발자와 관련 정보를 담고 있는 FGameplayContext를
래핑하여 사용하기 쉽게 도와주는 FGameplayContextHandle을 생성합니다.
그 다음에 해당 Handle로부터 GameplayEffect를 래핑하여 사용하기 쉽게 도와주는
GameplayEffectSpec을 블루 프린트에서 생성하도록 하는 GameplayEffectSpecHandle을 생성합니다.
최종적으로 만들어진 GameplayEffectSpecHandle에 저장된 GameplayEffect를
타깃, 즉 해당하는 캐릭터의 ASC에 부여합니다.
2) AuraCharacterPlayer
.
.
.
void AAuraPlayer::InitAbilityActorInfo()
{
.
.
.
InitializePrimaryAttribute();
}
우선, 다른 캐릭터의 설정이 완료되지 않았으므로 플레이어에게 먼저 설정하겠습니다.
InitAbilityActorInfo의 경우, ASC와 AttributeSet이 모두 설정되는 함수이므로
로직의 제일 마지막에 InitializePriamaryAttribute를 호출합니다.
이때 설계과정에서 선택할 수 있는데,
서버에서만 InitializePriamaryAttribute를 호출할 수 있고,
서버와 클라이언트 양쪽에서 InitializePriamaryAttribute를 호출할 수 있습니다.
서버에서만 수행하는 경우, Attribute가 이미 Replicate되고 있으므로
변경이 서버에서 전파되어 클라이언트에게 전달됩니다.
서버와 클라이언트 양쪽에서 수행하는 경우, 따로 Replicate하지 않아 시간이 단축됩니다.
따라서 서버와 클라이언트 양쪽에서 InitializePriamaryAttribute를 수행하겠습니다.
3) GE_Aura_PrimaryAttribute
수행하는 GE의 이름은 위와 같습니다.
우선, Duration Policy는 다음과 같습니다.
다음으로는 Modifier의 설정입니다.
이후 플레이어의 블루 프린트에서 GE를 설정합니다.
최종 실행결과는 다음과 같습니다.
'언리얼 > 게임 프로젝트' 카테고리의 다른 글
GameplayAbilitySystem을 이용한 RPG 프로젝트 - (32) GE의 모디파이어_Attribute Based 파헤치기 02 (0) | 2025.01.24 |
---|---|
GameplayAbilitySystem을 이용한 RPG 프로젝트 - (31) GE의 모디파이어_Attribute Based 파헤치기 01 (0) | 2025.01.24 |
GameplayAbilitySystem을 이용한 RPG 프로젝트 - (29) 데이터 테이블을 통한 Attribute 초기 (0) | 2025.01.23 |
Lyra 클론코딩 - (10 - 1) Input_01 (0) | 2025.01.23 |
다커 앤 다커 모작 - 6일차_아이템 #11 (0) | 2025.01.23 |