0. Data 내부 접근이 안되는 문제발생
*해결 : f12를 눌러 정의부로이동 -> 원본헤더파일을 인클루드!!
#include "GameplayEffectExtension.h"
1. Data 안에 수많은 정보들이 있는걸 볼수있다.
디버깅, 브레이크포인트를 걸어보면
void UAuraAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
2. Target, Source의 Data들을 채워넣는 실습
void UAuraAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{
Super::PostGameplayEffectExecute(Data);
// Soruce == causer of effect , Target = target of the effect(owner of AS)
const FGameplayEffectContextHandle EffectContextHandle = Data.EffectSpec.GetContext();
const UAbilitySystemComponent* SourceASC = EffectContextHandle.GetOriginalInstigatorAbilitySystemComponent();
//널체크
if(IsValid(SourceASC) && SourceASC->AbilityActorInfo.IsValid() && SourceASC->AbilityActorInfo->AvatarActor.IsValid())
{
AActor* SourceAvatarActor = SourceASC->AbilityActorInfo->AvatarActor.Get();
//소스의 컨트롤러얻기
const AController* SourceController = SourceASC->AbilityActorInfo->PlayerController.Get();
//소스의 컨트롤러가 널인경우, (아바타)액터를 폰에 캐스팅하여, 액터자체어서 컨트롤러를 가져옴
if(SourceController==nullptr &&SourceAvatarActor!=nullptr)
{
if(const APawn* Pawn = Cast<APawn>(SourceAvatarActor))
{
SourceController = Pawn->GetController();
}
}
if(SourceController!=nullptr)
{
ACharacter* SourceCharacter = Cast<ACharacter>(SourceController->GetPawn());
}
}
if(Data.Target.AbilityActorInfo.IsValid() && Data.Target.AbilityActorInfo->AvatarActor.IsValid())
{
AActor* TargetAvatarActor = Data.Target.AbilityActorInfo->AvatarActor.Get();
AController* TargetController = Data.Target.AbilityActorInfo->PlayerController.Get();
ACharacter* TargetCharacter = Cast<ACharacter>(TargetAvatarActor);
UAbilitySystemComponent* TargetASC = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetAvatarActor);
}
}
3.Refactor : 구조체에 값을 저장하고 관리하도록 리팩토링
//Source, Target의 데이터를 저장하는 구조체
USTRUCT()
struct FEffectProperties
{
GENERATED_BODY()
FEffectProperties(){} //기본생성자
FGameplayEffectContextHandle EffectContextHandle;
UPROPERTY()
UAbilitySystemComponent* SourceASC = nullptr;
UPROPERTY()
AActor* SourceAvatarActor = nullptr;
UPROPERTY()
AController* SourceController = nullptr;
UPROPERTY()
ACharacter* SourceCharacter=nullptr;
UPROPERTY()
UAbilitySystemComponent* TargetASC = nullptr;
UPROPERTY()
AActor* TargetAvatarActor = nullptr;
UPROPERTY()
AController* TargetController = nullptr;
UPROPERTY()
ACharacter* TargetCharacter=nullptr;
};
void UAuraAttributeSet::SetEffectProperties(const FGameplayEffectModCallbackData& Data, FEffectProperties& Props) const
{
// Soruce == causer of effect , Target = target of the effect(owner of AS)
Props.EffectContextHandle = Data.EffectSpec.GetContext();
Props.SourceASC = Props.EffectContextHandle.GetOriginalInstigatorAbilitySystemComponent();
//널체크
if(IsValid(Props.SourceASC) && Props.SourceASC->AbilityActorInfo.IsValid() && Props.SourceASC->AbilityActorInfo->AvatarActor.IsValid())
{
Props.SourceAvatarActor = Props.SourceASC->AbilityActorInfo->AvatarActor.Get();
//소스의 컨트롤러얻기
Props.SourceController = Props.SourceASC->AbilityActorInfo->PlayerController.Get();
//소스의 컨트롤러가 널인경우, (아바타)액터를 폰에 캐스팅하여, 액터자체어서 컨트롤러를 가져옴
if(Props.SourceController==nullptr &&Props.SourceAvatarActor!=nullptr)
{
if(const APawn* Pawn = Cast<APawn>(Props.SourceAvatarActor))
{
Props.SourceController = Pawn->GetController();
}
}
if(Props.SourceController!=nullptr)
{
Props.SourceCharacter = Cast<ACharacter>(Props.SourceController->GetPawn());
}
}
if(Data.Target.AbilityActorInfo.IsValid() && Data.Target.AbilityActorInfo->AvatarActor.IsValid())
{
Props.TargetAvatarActor = Data.Target.AbilityActorInfo->AvatarActor.Get();
Props.TargetController = Data.Target.AbilityActorInfo->PlayerController.Get();
Props.TargetCharacter = Cast<ACharacter>(Props.TargetAvatarActor);
Props.TargetASC = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(Props.TargetAvatarActor);
}
}
4. 결과 :
Props.만 찍으면 원하는 정보를 쉽게 get할수있다.
이걸가지고 재밌는 게임을 만들면 된다.
4. Qualifier 'const' is only allowed on non-static member functions 오류해결
UAuraAttributeSet::SetEffectProperties
함수이름앞에 클래스이름:: 붙여줘야 멤버함수로 간주 -> const 가능!
'UE5 > GameplayEffect' 카테고리의 다른 글
[UE5] GE Quiz (0) | 2024.06.02 |
---|---|
[UE5] 커브테이블 만들기 // GE 하드코딩 해결, 포션레벨별 회복량 만들기 (0) | 2024.06.02 |
[UE5] PreAttributeChange // 체력,마나 min-max 제한하는법 (0) | 2024.06.02 |
[UE5] Infinite이펙트 만들기 // 불에 닿으면 피감소 구현 (0) | 2024.06.02 |
[UE5] Stacking // 포션을 한번에 여러개 먹을시 제한설정 (0) | 2024.06.02 |