728x90
반응형
이번 포스트에서는 이전에 추가만 해놓은 Secondary Attribute를 GE를 통해 초기화하겠습니다.
이 과정은 Primary Attribute를 초기화하는 것과 매우 동일하므로
기존의 구조를 리팩토링하여 유연성과 확장성을 높히도록 하겠습니다.
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
{
GENERATED_BODY()
.
.
.
/*
* GAS Section
*/
.
.
.
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Attributes")
TSubclassOf<UGameplayEffect> DefaultSecondaryAttributes;
protected:
/*
* Attribute Section
*/
void ApplyEffectToSelf(TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level) const;
void InitializeDefaultAttributes() const;
};
.
.
.
void AAuraCharacterBase::ApplyEffectToSelf(TSubclassOf<UGameplayEffect> GameplayEffectClass, float Level) const
{
check(IsValid(GetAbilitySystemComponent()));
check(GameplayEffectClass);
FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
ContextHandle.AddSourceObject(this);
const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(GameplayEffectClass, Level, ContextHandle);
GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*SpecHandle.Data.Get(), GetAbilitySystemComponent());
}
void AAuraCharacterBase::InitializeDefaultAttributes() const
{
ApplyEffectToSelf(DefaultPrimaryAttributes, 1.f);
ApplyEffectToSelf(DefaultSecondaryAttributes, 1.f);
}
Secondary Attribute를 초기화하는 GE는 반드시
Primary Attribute를 초기화하는 GE 다음으로 수행되야 합니다.
따라서 Attribute를 초기화하는 모든 GE를 적용하는 InitializeDefaultAttribute에서는
로직의 순서를 위와 같이 구성하여 실행합니다.
2) AuraPlayer
void AAuraPlayer::InitAbilityActorInfo()
{
.
.
.
InitializeDefaultAttributes();
}
IniAbilityActorInfo에서의 기존의 로직을 위와 같이 수정합니다.
3) 언리얼 에디터
SecondaryAttribute를 초기화하는 새로운 GameplayEffect 블루 프린트를 생성하고 다음과 같이 설정합니다.
그리고 해당 GE의 Duration Policy는 Instant로 설정하여 영구히 적용하도록 합니다.
Player의 블루 프린트에 위와 같이 SecondaryAttribute를 초기화하는 GE를 설정하였습니다.
실제 실행 결과는 다음과 같습니다.
728x90
반응형
'언리얼 > 게임 프로젝트' 카테고리의 다른 글
Lyra 클론코딩 - (13) GameFeature Activate (0) | 2025.01.26 |
---|---|
Lyra 클론코딩 - (12) Portal UserFacingExpereience Load (0) | 2025.01.26 |
GameplayAbilitySystem을 이용한 RPG 프로젝트 - (34) Attribute와 연관된 Attribute (0) | 2025.01.25 |
Lyra 클론코딩 - (11) Common User (0) | 2025.01.25 |
GameplayAbilitySystem을 이용한 RPG 프로젝트 - (33) GE의 모디파이어_Attribute Based 파헤치기 03 (0) | 2025.01.25 |