初学GAS,仅用作自己查缺补漏,不想再做时又去找视频
参考教程:
英文原版(联机):Ambience Lee:
https://www.udemy.com/course/introduction-to-unreal-engine-4-ability-system/
中文翻译重置(单机):小明:
https://space.bilibili.com/149146076/channel/detail?cid=127939&ctype=0
一、插件环境
1.1、在Editor中勾选GameplayAbility并关闭
1.2、在.Build.cs中添加对应模块
PrivateDependencyModuleNames.AddRange(new string[] { "GameplayAbilities","GameplayTags","GameplayTasks" });
二、Character类配置
2.1、添加UAbilitySystemCompnent
2.2、并继承IAbilitySystemInterface
2.3、重写GetAbilitySystemComponent()
2.4、写一个可以让蓝图获取能力的接口AquireAbility
.h:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "AbilitySystemInterface.h"
#include "MyGASCharacter.generated.h"
UCLASS()
class GASTEST_API AMyGASCharacter : public ACharacter,public IAbilitySystemInterface
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMyGASCharacter();
UFUNCTION(BlueprintPure)
virtual UAbilitySystemComponent* GetAbilitySystemComponent() const;
UFUNCTION(BlueprintCallable)
void AquireAbility(TSubclassOf<class UGameplayAbility> InAbility);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
UPROPERTY(VisibleAnywhere,BlueprintReadOnly)
class UAbilitySystemComponent* AbilitySystemComp;
};
.cpp
#include "MyGASCharacter.h"
#include "AbilitySystemComponent.h"
// Sets default values
AMyGASCharacter::AMyGASCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
AbilitySystemComp = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("AbilitySystemComp"));
}
UAbilitySystemComponent* AMyGASCharacter::GetAbilitySystemComponent() const
{
return AbilitySystemComp;
}
void AMyGASCharacter::AquireAbility(TSubclassOf<class UGameplayAbility> InAbility)
{
if (AbilitySystemComp)
{
if (HasAuthority()&&InAbility)
{
AbilitySystemComp->GiveAbility(FGameplayAbilitySpec(InAbility, 1,0));
}
AbilitySystemComp->InitAbilityActorInfo(this, this);
}
}
// Called when the game starts or when spawned
void AMyGASCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyGASCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMyGASCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
此时,我们已经拥有了一个可以简单使用能力系统的角色