๐ ์ ๋ฐ๋ฏธ GAS ๊ฐ์ ์ค ๊ธฐ๋กํด๋๊ณ ์ถ์ ๋ด์ฉ์ ์ ์ด๋ ํฌ์คํธ
Section 2 : GAS์ ๋ํ ๊ธฐ๋ณธ ์ค๋ช ๊ณผ ์ ์
{ํ๋ก์ ํธ๋ช
}.bulid.cs
"GameplayAbilities"PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "EnhancedInput", "GameplayAbilities" });
GetAbilitySystemComponent() ์ฌ์ฉ (์์๊ฐ์ํจ์๋ก ์ ์๋์ด์์)UAbilitySystemComponent* AAuraCharacterBase::GetAbilitySystemComponent() const
{
return AbilitySystemComponent;
}
๋ฐ๋์ผ์ดํธ ์๋ฒ : ํ๋ ์ด์ด X, ๋ ๋๋ง X
๋ฆฌ์จ ์๋ฒ : ํ๋ ์ด์ด๊ฐ ์ง์ ํธ์คํ
, ํธ์คํธ๋ ์ง์ฐ์๊ฐ X

๋ฐ์ดํฐ ์ ํจ์ฑ์ ์๋ฒ๊ฐ ๊ธฐ์ค์ ์ด ๋๋ค.
๋ชจ๋ ์ปจํธ๋กค๋ฌ์ ๋ํ ๊ถํ์ ์๋ฒ๊ฐ ๊ฐ์ง๋ฉฐ ํด๋ผ๋ ๊ฐ์๊ฐ ์์ ํ ์ปจํธ๋กค๋ฌ๋ง ๊ด๋ฆฌํ๋ค
ํ๋ ์ด์ด ์คํ
์ดํธ ์ ๋ณด๋ ํด๋ผ์ด์ธํธ์๋ ๋ชจ๋ ์กด์ฌํ๋ค.
HUD,Widget์ ํด๋ผ์ด์ธํธ์๋ง ์กด์ฌํ๋ฉด ๋๋ค.
Replication์ ์๋ฒ -> ํด๋ผ ๋จ๋ฐฉํฅ์ด๋ค.
์บ๋ฆญํฐ์ ๋ฉค๋ฒ์ธ ๊ฒฝ์ฐ
์ง์ ์์ฑ ํ ํ ๋นํ๋ฉด ๋๋ค.
AAuraEnemy::AAuraEnemy()
{
AbilitySystemComponent = CreateDefaultSubobject<UAuraAbilitySystemComponent>("AbilitySystemComponent");
// ๋ฆฌํ๋ฆฌ์ผ์ด์
์ฌ์ฉ
AbilitySystemComponent->SetIsReplicated(true);
// AI์ฌ์ Minial ๋ชจ๋๋ก ์ฌ์ฉ
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);
}
ํ๋ ์ด์ด ์คํ ์ดํธ์ ๋ฉค๋ฒ์ธ ๊ฒฝ์ฐ
์คํ ์ดํธ์์ ์์ฑ ํ ์บ๋ฆญํฐ์ ํ ๋นํ๋ค.
AAuraPlayerState::AAuraPlayerState()
{
AbilitySystemComponent = CreateDefaultSubobject<UAuraAbilitySystemComponent>("AbilitySystemComponent");
// ๋ฆฌํ๋ฆฌ์ผ์ด์
์ฌ์ฉ
AbilitySystemComponent->SetIsReplicated(true);
// ํ๋ ์ด์ด์์ ์ธ ๊ฑฐ๋ผ Mixed ๋ชจ๋ ์ฌ์ฉ
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
}

ASC๋ 2๊ฐ์ Actor ์ ๋ณด๋ฅผ ์ฌ์ฉํ๋ค.
OwnerActor
AvatarActor : Owner๊ฐ ์บ๋ฆญํฐ๊ฐ ์๋ ๊ฒฝ์ฐ ์บ๋ฆญํฐ์ ์ ๊ทผํ๊ธฐ ์ฉ์ดํจ
Player Controlled Character ์์์ฒ๋ผ PlayerState๊ฐ ASC๋ฅผ ๋ค๊ณ ์๋ ๊ฒฝ์ฐ
ASC์ OwnerActor๋ PlayerState๊ฐ ๋๊ณ AvatarActor๋ Character๊ฐ ๋๋ค.
์กํฐ๊ฐ ๋ชจ๋ ์์ฑ๋ ์ดํ ASC์ AbliltyActorInfo๋ฅผ ํ ๋นํด์ผํ๋ฏ๋ก Possession์ด ์ผ์ด๋ ์ดํ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ๋ค.

- ํ๋ ์ด์ด ์บ๋ฆญํฐ
1-1. Pawn์ด ASC๋ฅผ ๋ค๊ณ ์๋ ๊ฒฝ์ฐ
PossessedBy()AcknowledgePossession()1-2. PlayerState๊ฐ ASC๋ฅผ ๋ค๊ณ ์๋ ๊ฒฝ์ฐ
PossessedBy()OnRep_PlayerState() : RepNotify ์ฌ์ฉ-> 1-2์ ๊ฒฝ์ฐ ASC๊ฐ PlayerState์ ๋ค์ด์๊ธฐ ๋๋ฌธ์ PlayerState๊ฐ Validํ์ง๋ ์ฒดํฌํด์ผํ๊ธฐ ๋๋ฌธ์ RepNotify๋ก ํ์ธํ๋ ๊ฒ
-> PlayerState๊ฐ ๋ฆฌํ๋ฆฌ์ผ์ด์
๋๋ ์์ ์๋ ํ๋ ์ด์ด ์ปจํธ๋กค๋ฌ๊ฐ Possess๋ ์ดํ์ด๋ฏ๋ก ์์ ํ๋ค.
void AAuraCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
// ์๋ฒ ์ ์ฉ
//if (HasAuthority()) ์ฒดํฌ ์ ํด๋ ๋๋ ๊ฒ ์ด๋ฏธ Server์์๋ง ํธ์ถ๋๋ ํจ์์
InitAbilityActorInfo();
}
void AAuraCharacter::OnRep_PlayerState()
{
Super::OnRep_PlayerState();
// ํด๋ผ์ด์ธํธ ์ ์ฉ
InitAbilityActorInfo();
}
// InitAbilityActorInfo๋ ํธ์ถํ๊ณ State๊ฐ ์์ฑํด๋ ์ปดํฌ๋ํธ๋ ์บ๋ฆญํฐ์ ํ ๋นํด์ฃผ๋ ๋๊ฐ์ง ์ญํ
void AAuraCharacter::InitAbilityActorInfo()
{
AAuraPlayerState* PlayerState = GetPlayerState<AAuraPlayerState>(); // ํ
ํ๋ฆฟ ๋ฒ์ ์ด ์์
check(PlayerState);
AbilitySystemComponent = PlayerState->GetAbilitySystemComponent();
AbilitySystemComponent->InitAbilityActorInfo(PlayerState, this); // OwnerActor != AvatarActor
}
- AI ์บ๋ฆญํฐ
์์ ์์ AI ์บ๋ฆญํฐ๋ ์ง์ ASC๋ฅผ ๋ค๊ณ ์๊ณ , ์ผ๋ฐ์ ์ผ๋ก BeginPlay ์์ ์์ ์ปจํธ๋กค๋ฌ ํ ๋น๋ ๋์ด์๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก BeginPlay์์ ํธ์ถํ๋ค.
void AAuraEnemy::BeginPlay()
{
Super::BeginPlay();
AbilitySystemComponent->InitAbilityActorInfo(this,this); // OwnerActor == AvatarActor
}

ASC ๋ฆฌํ๋ฆฌ์ผ์ด์ ๋ชจ๋๋ 3๊ฐ์ง๊ฐ ์๋ค.
์ฃผ์ ์ฌํญ
Mixed ๋ชจ๋ ์ฌ์ฉ์ ASC์ OwnerActor์ Owner๋ ํญ์ Controller ํด๋์ค์ฌ์ผํ๋ค.
https://github.com/jongmin7759/Unreal_GAS/commit/e651ac220a9aa7b74f10b4b3d3e344510e289ef1