GAS 공통 참고 강의 및 문서
주의 : 틀린 내용이 있을 수 있음. 5.1.1 버전으로 작성
https://www.udemy.com/course/unreal-engine-5-gas-top-down-rpg/?couponCode=ST15MT31224
https://github.com/tranek/GASDocumentation
GitHub - tranek/GASDocumentation: My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer s
My understanding of Unreal Engine 5's GameplayAbilitySystem plugin with a simple multiplayer sample project. - tranek/GASDocumentation
github.com
https://docs.unrealengine.com/5.1/en-US/gameplay-ability-system-for-unreal-engine/
Gameplay Ability System
High-level view of the Gameplay Ability System
docs.unrealengine.com
Using Gameplay Tags in Unreal Engine
An overview of the hierarchical label system in Unreal Engine.
dev.epicgames.com
Gameplay Tag를 정의하고 추가하는 방법은 크게 3가지이다.
1. 프로젝트 세팅에서 직접 추가/제거 하기
2. Data Table 에셋을 임포트(GameplayTagTableRow 사용)
3. C++에서 정의
1번과 2번 같은 경우에는 가장 간단하게 Gameplay Tag를 추가하는 방법이다. 특히 GameplayTagTableRow를 이용한다면 json, csv 파일을 이용할 수도 있음으로 테이블을 이용해 직관적으로 관리할 수 있다.
(1번과 2번같은 경우는 추가 참고 문서를 확인하자)
그러면 C++을 이용해서 Gameplay Tag를 어떻게 정의(추가)하고 사용할 수 있을까?
1. AssetManager와 싱글톤 이용
당연히 C++을 통해 추가를 한 후에, 우리는 에디터에서 동일하게 Gameplay Tag를 사용할 수 있어야 한다.
즉 빌드가 끝나면 Gameplay Tag가 추가되어야 한다. 런타임에서 추가(마찬가지로 제거도) 하는 것이 아니다.
이 방법은 에픽게임즈에서 제공하는 샘플프로젝트 중 하나인 Lyra에서 사용한 방법이다.
https://dev.epicgames.com/documentation/en-us/unreal-engine/lyra-sample-game-in-unreal-engine
Lyra Sample Game in Unreal Engine
Explore how to develop projects in UE5 using techniques from the Lyra Sample Game in Unreal Engine.
dev.epicgames.com
Enhanced Input Binding with Gameplay Tags C++ | Tutorial
This tutorial covers setting up a foundational Enhanced Input system in the First Person Template. This a minimalized version of the system implemented ...
dev.epicgames.com
위 게시글에도 잘 나와있다.
Lyra에서 구현방법을 보고싶다면 아래 파일들을 참고하자.
Lyra/Source/LyraGame/System/LyraAssetManager.cpp 및 ULyraAssetManager::InitializeAbilitySystem()
Lyra/Source/LyraGame/LyraGameplayTags.h
Lyra/Source/LyraGame/LyraGameplayTags.cpp
NativeGameplayTag (C++에서 작성된 GameplayTag)를 추가하기 위해서는 GameplayTagsManager에서 AddNativeGameplayTag 함수를 호출한다. GameplayTagsManager는 매니저(싱글톤) 클래스이다.
// in GameplayTagsManager.h
/**
* Registers the given name as a gameplay tag, and tracks that it is being directly referenced from code
* This can only be called during engine initialization, the table needs to be locked down before replication
*
* @param TagName The Name of the tag to add
* @param TagDevComment The developer comment clarifying the usage of the tag
*
* @return Will return the corresponding FGameplayTag
*/
FGameplayTag AddNativeGameplayTag(FName TagName, const FString& TagDevComment = TEXT("(Native)"));
단 함수 설명을 보듯이 This can only be called during engine initialization. 즉 엔진이 초기화 되는동안 호출되어야 한다. 즉 AddOwnGameplayTags 함수는 엔진이 초기화 되는동안 호출되어야한다. 어디서 호출을 해야할까?
Lyra(및 GAS 강의, Enhanced Input Binding 게시글)는 AssetManager 클래스를 이용한다.
따라서 C++로 GameplayTag를 추가하기 위해서는 AssetManager 클래스를 오버라이드 한 클래스와, GameplayTags를 추가 및 관리할 클래스가 필요하다.
GameplayTags를 추가 및 관리를 위해 보통 싱글톤 패턴을 이용한다. GameplayTag에 쉽게 접근함은 물론 AssetManager 클래스에서도 GameplayTag 초기화(추가)함수를 호출하기 위해서이다.
1. CustomGameplayTags 구조체 생성
CutomGameplayTags.h
#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
/**
* AuraGameplayTags
* Singleton containing native Gameplay Tags
*/
struct FAuraGameplayTags
{
public:
static const FAuraGameplayTags& Get() {return GameplayTags;}
static void InitializeNativeGameplayTags();
FGameplayTag Attributes_Primary_Strength;
FGameplayTag Attributes_Primary_Intelligence;
FGameplayTag Attributes_Primary_Resilience;
FGameplayTag Attributes_Primary_Vigor;
private:
static FAuraGameplayTags GameplayTags;
};
CutomGameplayTags.cpp
#include "AuraGameplayTags.h"
#include "GameplayTagsManager.h"
FAuraGameplayTags FAuraGameplayTags::GameplayTags;
void FAuraGameplayTags::InitializeNativeGameplayTags()
{
GameplayTags.Attributes_Primary_Strength = UGameplayTagsManager::Get().AddNativeGameplayTag(
FName("Attributes.Primary.Strength"),
FString("Increases physical damage")
);
GameplayTags.Attributes_Primary_Intelligence = UGameplayTagsManager::Get().AddNativeGameplayTag(
FName("Attributes.Primary.Intelligence"),
FString("Increases magical damage")
);
GameplayTags.Attributes_Primary_Resilience = UGameplayTagsManager::Get().AddNativeGameplayTag(
FName("Attributes.Primary.Resilience"),
FString("Increases Armor and Armor Penetration")
);
GameplayTags.Attributes_Primary_Vigor = UGameplayTagsManager::Get().AddNativeGameplayTag(
FName("Attributes.Primary.Vigor"),
FString("Increases Health")
);
}
싱글톤 구조체를 만들기 위해 private static 변수와 Get()함수가 필요하다.
또한 AssetManager에서 호출하여 엔진 초기화 중 AddNativeGameplayTag() 함수를 실행시켜줄 함수인 InitializeNativeGameplayTags() 함수를 추가한다.
2. CustomAssetManager 생성
CustomAssetManager.h
#pragma once
#include "CoreMinimal.h"
#include "Engine/AssetManager.h"
#include "AuraAssetManager.generated.h"
/**
*
*/
UCLASS()
class AURA_API UAuraAssetManager : public UAssetManager
{
GENERATED_BODY()
public:
static UAuraAssetManager& Get();
protected:
virtual void StartInitialLoading() override;
};
CustomAssetManager.cpp
#include "AuraAssetManager.h"
#include "AbilitySystemGlobals.h"
#include "AuraGameplayTags.h"
UAuraAssetManager& UAuraAssetManager::Get()
{
check(GEngine);
UAuraAssetManager* AuraAssetManager = Cast<UAuraAssetManager>(GEngine->AssetManager);
return *AuraAssetManager;
}
void UAuraAssetManager::StartInitialLoading()
{
Super::StartInitialLoading();
FAuraGameplayTags::InitializeNativeGameplayTags();
}
앞서 말했듯이 엔진 초기화중에 AddNativeGameplayTag를 호출할 방법이 필요하며 AssetManager가 적합하다.
StartInitialLoading()함수를 통해 CustomGameplayTags 싱글톤의 InitializeNativeGameplayTags()함수를 호출한다.
또한 AssetManager도 매니저 클래스(싱글톤)으로 Get()함수을 통해 CustomAssetManager 클래스를 반환하도록 만든다.
2. 매크로 이용 (추후 작성, 공부 필요)
'Unreal Engine > GAS' 카테고리의 다른 글
Creating own Gameplay Effect Context (1) | 2024.03.22 |
---|---|
Gameplay Tag (0) | 2024.03.15 |
GameplayEffect (0) | 2024.03.13 |