Mini

[UE5] GAS Ability Actor Info // 능력 정보초기화 하는방법 본문

UE5/GAS

[UE5] GAS Ability Actor Info // 능력 정보초기화 하는방법

Mini_96 2024. 5. 26. 19:46

1. 오너 vs 아바타

오너 : 컴포넌트의 소유자

아바타 : 능력의 대상

적의 경우 : 둘이같음

플레이어의경우 : 소유자는 PS임, 대상은 Player

초기화 함수

 

2. 초기화 함수는 빙의 이후에 수행되야한다

* Player 초기화 && ASC가 PS내에 있는경우 

Possedby에서 초기화 => 서버를 위해 초기화

OnRep_PS에서 초기화 => 클라를 위해 초기화

2번 초기화 해줘야함.

 

* Player 초기화 && ASC가 Player내에 있는경우

Possedby에서 초기화 => 서버를 위해 초기화

AcknowledgePossession에서 초기화 => 클라를 위해 초기화

 

* 적의경우

비긴플레이에서 초기화해주면됨

 

3. 구현

1. 적의경우

멤버변수로 ASC, AS를 갖고있기 때문에

비긴플레이어서 초기화하면 된다.

void AAuraEnemy::BeginPlay()
{
	Super::BeginPlay();
	// 능력 시스템 컴포넌트를 초기화합니다.
	//첫 번째 this는 능력의 소유자(Owner)를, 두 번째 this는 능력이 적용될 대상(Actor)
	AbilitySystemComponent->InitAbilityActorInfo(this, this);
}

 

2. 플레이어의 경우

PS를 멤버변수로 선언하고, PS내의 ASC,AS에 접근하면 된다.

이때, ASC의 오너는 PS임에 주의

void AAuraCharacter::PossessedBy(AController* NewController)
{
	// 부모 클래스의 PossessedBy 함수 호출
	Super::PossessedBy(NewController);

	// 서버에서 능력 시스템 액터 정보를 초기화
	//init ability actor info for server
	InitAbilityActorInfo();
}

// 플레이어 상태가 복제될 때 호출되는 함수
void AAuraCharacter::OnRep_PlayerState()
{
	// 부모 클래스의 OnRep_PlayerState 함수 호출
	Super::OnRep_PlayerState();

	// 클라이언트에서 능력 시스템 액터 정보를 초기화
	//init ability actor info for client
	InitAbilityActorInfo();
}

// 능력 시스템 액터 정보를 초기화하는 함수
void AAuraCharacter::InitAbilityActorInfo()
{
	// 플레이어 상태를 AAuraPlayerState 타입으로 가져옴
	AAuraPlayerState* AuraPlayerState = GetPlayerState<AAuraPlayerState>();
	// AuraPlayerState가 유효한지 확인
	check(AuraPlayerState);
	// AuraPlayerState의 능력 시스템 컴포넌트를 이용하여 액터 정보를 초기화
	//첫 번째 인자는 능력의 소유자(Owner)를, 두 번째 인자는 능력이 적용될 대상(Actor)
	AuraPlayerState->GetAbilitySystemComponent()->InitAbilityActorInfo(AuraPlayerState, this);
	// 이 캐릭터의 AbilitySystemComponent를 AuraPlayerState의 것으로 설정
	AbilitySystemComponent = AuraPlayerState->GetAbilitySystemComponent();
	// 이 캐릭터의 AttributeSet을 AuraPlayerState의 것으로 설정
	AttributeSet = AuraPlayerState->GetAttributeSet();

	
}

 

4. 믹스드 복제모드 주의

믹스드모드의 오너 기본값 :PS

ASC의 오너가 PS가 아닐경우 -> SetOwner로 지정해줘야한다!