UE4/5 GAS技能系统入门(上)

简介: UE4/5 GAS技能系统入门

Unreal的GAS技能系统是针对游戏技能管理的一套逻辑封装方案,这套方案考虑面较广,包括了Cooldowns技能冷却、允许多技能同时释放、GameplayTags的使用、特殊的事件触发等,今天就来学习一下。

1.激活插件与C++部分配置
1.1 创建测试工程,选择第三人称案例,C++工程。以便自动创建对应的sln文件。

1.2 以UE5.2版本进行演示,首先在插件管理器中激活GameplayAbilities插件:
q1.png

1.3 打开C++工程的build.cs文件,添加GameplayAbilities模块依赖:

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class MyProject : ModuleRules
{
   
   
    public MyProject(ReadOnlyTargetRules Target) : base(Target)
    {
   
   
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] {
   
    "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "EnhancedInput", "GameplayAbilities" });
    }
}

1.4 找到Character默认角色类的.h头文件,添加相关模块include并实现IAbilitySystemInterface接口:

//头文件
#include "AbilitySystemInterface.h"
#include "AbilitySystemComponent.h"
#include "Abilities/GameplayAbility.h"
//

//省略

//实现接口:
UCLASS(config=Game)
class AMyProjectCharacter : public ACharacter, public IAbilitySystemInterface
{
   
   
    GENERATED_BODY()

//省略

1.5 在Character默认角色类的.h头文件中,定义几个关键函数:

public:
    AMyProjectCharacter();
    //该字段为IAbilitySystemInterface接口暴露字段:
    UAbilitySystemComponent* GetAbilitySystemComponent()const override;

    //实现技能的蓝图必须挂载该组件:
    UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Abilities")
    class UAbilitySystemComponent* AbilitySystemComponent;

    //学习技能函数需要手动实现:
    UFUNCTION(BlueprintCallable, Category = "Abilities")
    void AquireAbility(TSubclassOf<UGameplayAbility>AbilityToAquire);

1.6 来到Character默认角色类的.cpp文件中,实现这几个函数:

AMyProjectCharacter::AMyProjectCharacter()
{
   
   
    //省略

    //构造函数中创建这个组件:
    AbilitySystemComponent = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("AbilitySystem"));
}
//省略

//实现GetAbilitySystemComponent,返回字段即可
UAbilitySystemComponent* AMyProject2Character::GetAbilitySystemComponent() const
{
   
   
    return AbilitySystemComponent;
}

//自行实现AquireAbility逻辑,其实就是调用内部的GiveAbility接口再初始化

void AMyProject2Character::AquireAbility(TSubclassOf<UGameplayAbility> AbilityToAquire)
{
   
   
    if (AbilitySystemComponent) {
   
   
         if (HasAuthority() && AbilityToAquire) {
   
   
             AbilitySystemComponent->GiveAbility(FGameplayAbilitySpec(AbilityToAquire, 1, 0));
        }
         AbilitySystemComponent->InitAbilityActorInfo(this, this);
    }
}

目前C++部分需要的工作已经处理完成。

相关文章
|
网络协议 编译器 Linux
FFMPEG音视频开发: 发布RTSP流(采用EasyDarwin作为流媒体服务器)
FFMPEG音视频开发: 发布RTSP流(采用EasyDarwin作为流媒体服务器)
1246 1
FFMPEG音视频开发: 发布RTSP流(采用EasyDarwin作为流媒体服务器)
|
5月前
|
监控 安全 数据安全/隐私保护
U盘如何防泄密?这几个技术手段迎刃而解
安得卫士提供U盘防泄密四大核心措施:准入控制、操作管控、行为审计与离线防护。通过注册授权、权限细分、敏感数据拦截、全流程操作审计及加密外发控制,实现U盘数据全周期安全防护,有效防范数据泄露风险。
316 6
|
网络协议 Shell Windows
搭建rtmp流媒体服务器的步骤
网络上很多问文章介绍使用ffmpeg推送和拉流,经常遗漏安装rtsp-simple-server的步骤,执行推流命令:
931 0
|
数据挖掘 程序员 Python
【Python】已解决:ModuleNotFoundError: No module named ‘Workbook’
【Python】已解决:ModuleNotFoundError: No module named ‘Workbook’
464 0
|
网络协议 安全 调度
关闭Windows自动更新的6种方法
本文介绍了六种关闭Windows自动更新的方法,包括使用服务管理器、组策略编辑器、修改注册表、任务计划程序、网络连接设置和命令行。
6979 0
|
人工智能 自然语言处理 IDE
人工智能|利用人工智能自动找bug
在程序员编程的过程中,产生Bug是一件稀松平常的事情,以前在编码的过程中提前找出Bug,需要通过单元测试、CodeReview等各种方式。 当今,人工智能技术的发展给软件开发和测试带来了许多机会。利用人工智能技术,可以开发出自动化的 bug 检测工具,从而提高软件质量和可靠性。
|
设计模式 JavaScript 前端开发
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
Vue3报错Property “xxx“ was accessed during render but is not defined on instance
UE5ControlRig脚部IK匹配地面(FootIK)的简易实现
UE5ControlRig脚部IK匹配地面(FootIK)的简易实现
833 0
UE5ControlRig脚部IK匹配地面(FootIK)的简易实现
|
前端开发 开发工具 git
git rebase 和 git merge的区别?以及你对它们的理解?
git rebase 和 git merge的区别?以及你对它们的理解?
485 1
|
自然语言处理 Python
Python读取Word/PPT文件文本内容和图片内容
读取某个指定路径下的Word/PPT文件,并将其中所有的文本内容生成一个TXT文件,将所有的图片内容保存在一个文件夹里
1128 0

热门文章

最新文章