UE5/RPG Attributes
[UE5] 보조속성구현, 주요속성변경시 자동변경
Mini_96
2024. 6. 7. 02:14
1. res up => armor up 구현위해
res가 바뀔때마다, armor가 바뀐다
구현 : Infinity GE를 만들면 됨
2.캐릭베이스에 Secondary속성추가
when사용? : 기본속성에 의존 -> 기본속성이 set된 이후 실행이 바람직함
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Attributes")
TSubclassOf<UGameplayEffect> DefaultPrimaryAttributes;
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Attributes")
TSubclassOf<UGameplayEffect> DefaultSecondaryAttributes;
3. 속성 초기화 함수 구현
void AAuraCharacterBase::InitializePrimaryAttributes() const
{
check(IsValid(GetAbilitySystemComponent())); //ASC확인
check(DefaultPrimaryAttributes); //GE확인
//1. Context Handle 만들기
const FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
//2. Effect Spec 만들기
const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(DefaultPrimaryAttributes, 1.f,ContextHandle);
GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*SpecHandle.Data.Get(), GetAbilitySystemComponent());
}
void AAuraCharacterBase::InitializeSecondaryAttributes() const
{
check(IsValid(GetAbilitySystemComponent())); //ASC확인
check(DefaultSecondaryAttributes); //GE확인
//1. Context Handle 만들기
const FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
//2. Effect Spec 만들기
const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(DefaultSecondaryAttributes, 1.f,ContextHandle);
GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*SpecHandle.Data.Get(), GetAbilitySystemComponent());
}
* 문제 : 반복되는코드가 많음 -> 매개변수로(class, level 빼서 통합)
4. 리팩토링
void AAuraCharacterBase::ApplyEffectToSelf(TSubclassOf<UGameplayEffect> GameplayEffect, float Level) const
{
check(IsValid(GetAbilitySystemComponent())); //ASC확인
check(GameplayEffect); //GE확인
//1. Context Handle 만들기
const FGameplayEffectContextHandle ContextHandle = GetAbilitySystemComponent()->MakeEffectContext();
//2. Effect Spec 만들기
const FGameplayEffectSpecHandle SpecHandle = GetAbilitySystemComponent()->MakeOutgoingSpec(GameplayEffect, Level,ContextHandle);
GetAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(*SpecHandle.Data.Get(), GetAbilitySystemComponent());
}
void AAuraCharacterBase::InitializeDefaultAttributes() const
{
ApplyEffectToSelf(DefaultPrimaryAttributes, 1.f);
ApplyEffectToSelf(DefaultSecondaryAttributes, 1.f);
}
5. 캐릭터에서 리팩토링한 함수로 함수교체
// 능력 시스템 액터 정보를 초기화하는 함수
void AAuraCharacter::InitAbilityActorInfo()
{
...
InitializeDefaultAttributes(); //정보
}
6. 에디터에서 Infinity GE 만들면됨
7. Res변경시 armor도 자동변경되는가? Yes!
armor가 Infinity이기때문에, Res가 오르면 , armor도 오른다.
8. 실습
*단점 : 속성이너무많아 화면에 안나옴
*해결 : 속성위젯 (다음챕터)