AGS课程笔记

AGS课程笔记
凝雨
第一章:添加玩家角色并控制
1 | 26-35 HUD血量和蓝量UI制作及更新数据 UI文件夹 AuraHUD Widget overlayWidget |
第一节:添加CPP基类
创建新项目
创建C++抽象角色类
玩家和怪物都继承自这个类,命名AuraCharacterBase,文件夹分类为Character
删除没必要的函数,修改
PrimaryActorTick.bCanEverTick = true为PrimaryActorTick.bCanEverTick = falseAAuraCharacterBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21// Fill out your copyright notice in the Description page of Project Settings.
UCLASS(Abstract)
class GAS_API AAuraCharacterBase : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAuraCharacterBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};- AAuraCharacterBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19// Fill out your copyright notice in the Description page of Project Settings.
// Sets default values
AAuraCharacterBase::AAuraCharacterBase()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void AAuraCharacterBase::BeginPlay()
{
Super::BeginPlay();
}添加装备组件
- AAuraCharacterBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26// Fill out your copyright notice in the Description page of Project Settings.
UCLASS(Abstract)
class GAS_API AAuraCharacterBase : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AAuraCharacterBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
//智能指针
UPROPERTY(EditAnywhere, Category = "Combat")
TObjectPtr<USkeletalMeshComponent>Weapon;
};- AAuraCharacterBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22// Fill out your copyright notice in the Description page of Project Settings.
// Sets default values
AAuraCharacterBase::AAuraCharacterBase()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
//挂载,设置碰撞
Weapon=CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
Weapon->SetupAttachment(GetMesh(), FName("WeaponSocket"));
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
// Called when the game starts or when spawned
void AAuraCharacterBase::BeginPlay()
{
Super::BeginPlay();
}创建继承自AuraCharacterBase的子类,分别为玩家Player和怪物Enemy
第二节:角色动画和装备武器
创建角色蓝图,继承C++子类,角色继承Player,怪物继承Enemy
将角色网格体设置为角色网格体
武器绑定
调整绑定武器
调整绑定武器
第三节 :角色状态机和动画
- 创建状态机
- 链接状态机
- 添加动画
- 链接混合动画
- 动画事件图表
- 打开角色蓝图
- 将角色拖到进场景测试
第四节:怪物动画
武器绑定同玩家的武器绑定
添加动画蓝图创建怪物动作模板
模板状态机
混合状态
添加怪物状态机
设置混合动画
第五节:增强输入系统
- 添加输入操作,
- 添加输入映射
添加玩家控制器C++类,Player文件夹
- 头文件AuraPlayerController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35// Fill out your copyright notice in the Description page of Project Settings.
class UInputMappingContext;
class UInputAction;
struct FInputActionValue;
/**
*
*/
UCLASS()
class GAS_API AAuraPlayerController : public APlayerController
{
GENERATED_BODY()
public:
AAuraPlayerController();
protected:
virtual void BeginPlay() override;
virtual void SetupInputComponent() override;
private:
UPROPERTY(EditAnywhere, category = "Input");
TObjectPtr<UInputMappingContext> AuraContext;
UPROPERTY(EditAnywhere, category = "Input");
TObjectPtr<UInputAction> MoveAction;
void Move(const FInputActionValue& InputActionValue);
};- 源文件AuraPlayerController.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61// Fill out your copyright notice in the Description page of Project Settings.
AAuraPlayerController::AAuraPlayerController()
{
bReplicates = true;
}
void AAuraPlayerController::BeginPlay()
{
Super::BeginPlay();
//检查输入映射是否有效
check(AuraContext);
//获取增强输入系统
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
//添加映射上下文
Subsystem->AddMappingContext(AuraContext, 0);
bShowMouseCursor = true;
DefaultMouseCursor = EMouseCursor::Default;
FInputModeGameAndUI InputModeData;
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
InputModeData.SetHideCursorDuringCapture(false);
SetInputMode(InputModeData);
}
void AAuraPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
}
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
{
const FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
if (APawn* ControlledPawn = GetPawn<APawn>())
{
ControlledPawn->AddMovementInput(RightDirection * InputAxisVector.Y);
ControlledPawn->AddMovementInput(ForwardDirection * InputAxisVector.X);
}
}- 创建继承自AuraPlayerController的蓝图类
- 选择控制器映射和控制器
- 添加游戏基础模式蓝图
- 选择玩家控制器及玩家蓝图
- 在游戏世界场景切换游戏模式,添加玩家出生点并运行
第六节:添加相机及设置角色选择
打开角色蓝图添加弹簧臂
弹簧臂下添加相机,通过调整弹簧臂设置相机位置及角度
前往玩家CPP类,AuraCharacter.h,控制玩家旋转
- 头文件AuraCharacter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19// Fill out your copyright notice in the Description page of Project Settings.
/**
*
*/
UCLASS()
class GAS_API AAuraCharacter : public AAuraCharacterBase
{
GENERATED_BODY()
public:
AAuraCharacter();
};- 源文件AuraCharacter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18// Fill out your copyright notice in the Description page of Project Settings.
AAuraCharacter::AAuraCharacter()
{
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->RotationRate=FRotator(0.0, 400.0f, 0.0);
GetCharacterMovement()->bConstrainToPlane=true;
GetCharacterMovement()->bSnapToPlaneAtStart=true;
bUseControllerRotationRoll = false;
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
}返回引擎,打开角色蓝图,将弹簧臂
yaw取消,将旋转朝向运动打开,设置旋转速率为500
第二章
1 | GAS, |
GE 属性初始化和UI显示等…
GamplayAbility 简称 GA,是UE引擎里的GAS内的功能组件,它的主要功能包括技能冷却时间(CD)和技能消耗的管理,同时也支持网络同步和实例支持。开发者可以在ActivateAbility事件中编写相关的技能逻辑,如角色动作、粒子效果以及角色数值的变动。根据技能是否施展成功,可以调用CommitAbility()或EndAbility()来结束技能。
————————————————
原文链接:https://blog.csdn.net/qq_30100043/article/details/137234914
第一节:添加接口
创建Interaction文件夹C++类EnemyInteraction
- EnemyInteraction头文件代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29// Fill out your copyright notice in the Description page of Project Settings.
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UEnemyInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class GAS_API IEnemyInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
//声明接口类
virtual void HighightActor()=0;
virtual void UnHighlightActor()=0;
};在怪物基类实现接口AuraEnemy.h
- 头文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22// Fill out your copyright notice in the Description page of Project Settings.
/**
*
*/
UCLASS() //继承接口类
class GAS_API AAuraEnemy : public AAuraCharacterBase,public IEnemyInterface
{
GENERATED_BODY()
public:
//实现接口函数
void HighightActor();
void UnHighlightActor();
};- 源文件
1
2
3
4
5
6
7
8
9
10
11
12
13// Fill out your copyright notice in the Description page of Project Settings.
//实现接口函数
void AAuraEnemy::HighightActor()
{
}
void AAuraEnemy::UnHighlightActor()
{
}
UI
创建血量UI
尺寸框控件-SizeBox_Root
覆盖控件-Overlay_Root
图片控件[背景]-Image_Background
进度条控件
- 样式-填充图=图片
- 样式-填充图-改为图形填充
- 百分比=1
- 下至上
- 外观-填充透明A=1
- 样式-背景-透明度=0
添加图片控件-比例
- 更新玻璃背景
- 设置填充大小
代码
用户控件基类
1 | // Fill out your copyright notice in the Description page of Project Settings. |
1 | // Fill out your copyright notice in the Description page of Project Settings. |
控制器
1 | // Fill out your copyright notice in the Description page of Project Settings. |
1 | // Fill out your copyright notice in the Description page of Project Settings. |
控制器子类
1 | // Fill out your copyright notice in the Description page of Project Settings. |
1 | // Fill out your copyright notice in the Description page of Project Settings. |
HUD
- 事件基本在这发出和绑定
1 | // Fill out your copyright notice in the Description page of Project Settings. |
1 | // Fill out your copyright notice in the Description page of Project Settings. |
AuraCharacter.cpp*********************************************为初始化的地方
1 | // Fill out your copyright notice in the Description page of Project Settings. |
配置GAS
第一节:添加CPP类和声明
打开插件添加UAbilitySystemComponent的c++类
添加UAttributeSet的c++类
在玩家基类添加前向声明
class UAbilitySystemComponent; class UAttributeSet;1
2
3
4
5
6
73. 玩家基类添加IAbilitySystemInterface接口
4. 声明IAbilitySystemInterface和UAttributeSet对象
5. 实现接口函数virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override
```cpp
return IAbilitySystemInterface实例
- 添加APlayerState c++类,将角色声明的UAbilitySystemComponent也复制一份进去,前向声明也需要
第二节:创建实例
- 玩家的需要在AAuraPlayerState构造函数上实例
1 | AAuraPlayerState::AAuraPlayerState() |
- 怪物的需要在怪物基类构造函数实例
1 | ACharacterEnemy::ACharacterEnemy() |
第三节:处理网络同步,如上注释
设置怪物和玩家网络同步AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal); 带面见上边
设置怪物代理,在BeginPlay函数下
1
2
3
4
5
6
7void ACharacterEnemy::BeginPlay()
{
Super::BeginPlay();
check(AbilitySystemComponent)
//初始化属性? 怪物自己持有,怪物自己代理
AbilitySystemComponent->InitAbilityActorInfo(this,this);
}设置玩家代理,在玩家基类下声明InitAbilityActorInfo()和重写两个虚函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14virtual void PossessedBy(AController* NewController) override;
void ACharacterBase::PossessedBy(AController* NewController)
{
//服务器
Super::PossessedBy(NewController);
InitAbilityActorInfo();
}
virtual void OnRep_PlayerState() override;
void ACharacterBase::OnRep_PlayerState()
{
//客户端
Super::OnRep_PlayerState();
InitAbilityActorInfo();
}实现 自己持有,代理玩家
1
2
3
4
5
6
7
8
9void ACharacterBase::InitAbilityActorInfo()
{
AAuraPlayerState* AuraPlayerState = GetPlayerState<AAuraPlayerState>();
check(AuraPlayerState);
AuraPlayerState->GetAbilitySystemComponent()->InitAbilityActorInfo(AuraPlayerState, this);
Cast<UAuraAbilitySystemComponent>(AuraPlayerState->GetAbilitySystemComponent())->AbilityActorInfoSet(); //漏写
AbilitySystemComponent = AuraPlayerState->GetAbilitySystemComponent();
AttributeSet = AuraPlayerState->GetAttributeSet();
}
第四节:属性声明
属性声明打开UAttributeSet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76// Fill out your copyright notice in the Description page of Project Settings.
/*在虚幻引擎5(UE5)中,UAttributeSet 是一个用于存储和管理游戏中实体(如角色、敌人等)属性的数据结构。
*它是基于 Unreal 的属性系统(Attribute System),该系统设计用于高效地处理和同步这些属性,尤其是在网络环境中。
UAttributeSet 类通常作为蓝图类或者C++类的一个成员变量来使用,
它允许开发者定义一系列属性,如生命值(Health)、魔法值(Mana)、力量(Strength)等,并提供了访问和修改这些属性值的接口。
这些属性可以被标记为需要在网络上同步,以便于多人游戏中的状态同步。
要创建自定义的 UAttributeSet 类,你需要继承自 UAttributeSet 并定义你的属性。
这通常涉及到使用 UPROPERTY() 宏来声明属性,并可能使用 UPROPERTY(Replicated) 来确保它们在网络上的客户端间正确同步。
此外,你可能还需要实现一些逻辑来处理属性的变化,例如当生命值减少到零时触发死亡事件*/
//设置访问宏
//在虚幻引擎(Unreal Engine)的C++编程中,
//ATTRIBUTE_ACCESSORS 是一个宏,用于自动生成属性(Attribute)的存取器(Getter 和 Setter)函数。
//这个宏常用于UAttributeSet子类中,以便于更便捷地操作游戏属性,如角色的生命值、能量、攻击力等
//使用 ATTRIBUTE_ACCESSORS 宏可以减少重复代码,让代码更加简洁且易于维护。
//它通常与属性声明一起使用,自动为你生成相应的函数来读取和设置 FGameplayAttributeData 中的属性值。
/**
*
*/
UCLASS()
class GASDEMO_API UAuraAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
UAuraAttributeSet();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
/*属性声明*/
//生命值
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Primary Attributes")
FGameplayAttributeData Health; //GameplayAttributeData 结构体是用来存储游戏属性的具体数值及其相关元数据的
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Health);
//最大生命值
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxHealth, Category = "Primary Attributes")
FGameplayAttributeData MaxHealth;
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, MaxHealth);
//魔法值
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Mana, Category = "Primary Attributes")
FGameplayAttributeData Mana;
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, Mana);
//最大魔法值
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxMana, Category = "Primary Attributes")
FGameplayAttributeData MaxMana;
ATTRIBUTE_ACCESSORS(UAuraAttributeSet, MaxMana);
/*属性函数*/
//在你的代码中,OnRep_Health 是一个 Unreal Engine 中的特殊函数,用于处理网络复制(replication)过程中属性发生变化的情况。
//当一个具有 replicated 属性的变量(在这个例子中似乎是Health,尽管它没有直接展示出来)在服务器上发生改变时,
//此函数会在所有相关的客户端上被调用来反映这一变化,确保所有玩家看到的游戏状态是一致的
UFUNCTION()
void OnRep_Health(const FGameplayAttributeData& OldHealth) const;
UFUNCTION()
void OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const;
UFUNCTION()
void OnRep_Mana(const FGameplayAttributeData& OldMana) const;
UFUNCTION()
void OnRep_MaxMana(const FGameplayAttributeData& OldMaxMana) const;
};1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64// Fill out your copyright notice in the Description page of Project Settings.
UAuraAttributeSet::UAuraAttributeSet()
{
//初始化属性
InitHealth(100.f);
InitMaxHealth(100.f);
InitMana(50.f);
InitMaxMana(50.f);
}
void UAuraAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
/*注册属性*/
//在Unreal Engine网络编程中,DOREPLIFETIME_CONDITION_NOTIFY 宏用于控制特定Actor或ActorComponent属性的生命周期管理,
//特别是关于其在网络中的复制行为。
//这个宏帮助你定义哪些属性应该在网络上同步,以及在什么条件下同步,同时还能在属性发生变化时触发自定义的通知回调。
//UAuraAttributeSet: 这里指定了属性所属的类,即属性集类,它通常继承自 UAttributeSet 并用于存储游戏角色的各种属性。
//Health: 指定要管理其网络生命周期的属性名。在这个上下文中,Health 是玩家或角色的一个关键属性,需要在网络环境中实时同步
//COND_None: 这是同步条件。COND_None 表示没有特别的条件限制,意味着无论何时只要属性值改变就会尝试进行同步。
//在其他情况下,可能会有比如仅当玩家拥有控制器 (COND_OwnerOnly) 或者仅当属性在特定范围内改变 (COND_SkipIfNotDirty) 等条件。
//EPNOTIFY_Always: 这决定何时触发通知回调。REPNOTIFY_Always 表明每次属性值改变时,不论是在服务器还是客户端,都会调用通知回调函数(通常是 OnRep_Health)。
//这意味着每次 Health 值发生变动,即使变动后的值与旧值相同,也会触发通知。
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, Health, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, MaxHealth, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, Mana, COND_None, REPNOTIFY_Always);
DOREPLIFETIME_CONDITION_NOTIFY(UAuraAttributeSet, MaxMana, COND_None, REPNOTIFY_Always);
}
/*属性函数实现*/
void UAuraAttributeSet::OnRep_Health(const FGameplayAttributeData& OldHealth) const
{
//宏的作用:此宏会在编译时期生成必要的代码来自动调用 OnRep_Health 函数,当 Health 属性的值在服务器上发生变化时。
//它确保了当属性的值由于服务器端的更新而有所不同时,所有相关的客户端都会得到通知,并执行相应的 OnRep_Health 回调。
//UAuraAttributeSet:这是属性集类的名称,即定义属性和复制逻辑的类。
//Health:这是你要为其添加复制通知的属性名称。这意味着每当 Health 属性的值发生变化时,框架都会自动处理网络同步。
//ldHealth:这是传递给 OnRep_Health 回调函数的参数名称,表示属性更改前的旧值。这允许你在回调中比较新旧值并做出相应处理
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, Health, OldHealth);
}
void UAuraAttributeSet::OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, MaxHealth, OldMaxHealth);
}
void UAuraAttributeSet::OnRep_Mana(const FGameplayAttributeData& OldMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, Mana, OldMana);
}
void UAuraAttributeSet::OnRep_MaxMana(const FGameplayAttributeData& OldMaxMana) const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UAuraAttributeSet, MaxMana, OldMaxMana);
}
项目
代码文件夹
| 文件夹 | 中文 |
|---|---|
| Ability System | 能力系统 |
| Actor | 演员 |
| AI | 人工智能 |
| Anim Notifies | 动画通知 |
| Characte | 角色 |
| checkpoint | 检查站,存档点 |
| Game | 游戏 |
| Input | 输入 |
| MainMenu | 主菜单 |
| Player | 玩家 |
| Spawn Volumes | 产卵量 |
| UI | UI |
Ability System
- Abilities 技能
- AbilityTasks 鼠标
| 类 | 描述 | 继承 |
|---|---|---|
| AuraGameplayAbility | 该C++类定义了一个游戏中的技能组件 | UGameplayAbility |
| UAuraDamageGameplayAbility | //该C++类定义了一个名为UAuraDamageGameplayAbility的游戏能力,继承自UAuraGameplayAbility。主要功能包括: // CauseDamage:对目标造成伤害。 // MakeDamageEffectParamsFromClassDefaults:根据类默认值生成伤害效果参数。 // GetDamageAtLevel:获取当前等级下的伤害值。 // 包含多个编辑器属性,如伤害类型、伤害值、减益效果等,用于配置伤害行为 | AuraGameplayAbility |
| UAuraPassiveAbility | // 该C++类定义了一个名为UAuraPassiveAbility的被动技能基类,继承自UAuraGameplayAbility。主要包含两个函数: // ActivateAbility:重写父类的激活能力函数,用于初始化被动技能。 // ReceiveDeactivate:接收并处理被动技能被移除或失效的情况,参数为一个游戏标签 | AuraGameplayAbility |
| UAuraSummonAbility | // 该C++类UAuraSummonAbility继承自UAuraGameplayAbility,主要用于游戏中的召唤功能。主要功能如下: // GetSpawnLocations:返回一系列用于召唤的位置向量。 // GetRandomMinionClass:返回一个随机的召唤物(小兵)类。 // NumMinions:设置需要召唤的小兵数量,默认为5。 // MinionClasses:存储可召唤的小兵类列表。 // MinSpawnDistance:设置最小召唤距离,默认为50单位。 // MaxSpawnDistance:设置最大召唤距离,默认为250单位。 // SpawnSpread:设置召唤物分布的角度范围,默认为90度。 | AuraGameplayAbility |
| UArcaneShards | //该C++类UArcaneShards继承自UAuraDamageGameplayAbility,主要用于游戏中的某种伤害能力。它包含: // 虚拟函数GetDescription,返回技能描述。 // 虚拟函数GetNextLevelDescription,返回升级后的技能描述。 // 成员变量MaxNumShards,存储最大碎片数量,默认为11。 | UAuraDamageGameplayAbility |
| UAuraBeamSpell | // 该C++类UAuraBeamSpell继承自UAuraDamageGameplayAbility,主要用于实现游戏中的一种光束法术能力。其主要功能包括: // 存储鼠标点击信息(位置和演员)。 // 追踪首个目标的位置。 // 存储额外的目标列表。 // 处理主要目标和额外目标死亡事件。 // 其中成员变量定义了鼠标点击位置、点击到的演员、拥有者控制器及角色等信息,并设置了最大可追踪目标数量为5。 | UAuraDamageGameplayAbility |
| UAuraFireBlast | // 该C++类UAuraFireBlast继承自UAuraDamageGameplayAbility,主要功能包括: // 生成火球描述文本(GetDescription和GetNextLevelDescription方法)。 // 召唤多个火球(通过SpawnFireBalls方法)。 // 定义了火球数量(NumFireBalls属性,默认为12)和火球类(FireBallClass属性) | UAuraDamageGameplayAbility |
| UAuraMeleeAttack | UAuraDamageGameplayAbility | |
| UElectrocute | // 该C++类UElectrocute继承自UAuraBeamSpell,主要用于实现游戏中的“电击”法术效果。其功能包括: // 重写GetDescription方法,用于获取当前等级的法术描述。 // 重写GetNextLevelDescription方法,用于获取升级后的法术描述。 | UAuraBeamSpell |
| UAuraFireBolt | UAuraProjectileSpell | |
| UElectrocute | UAuraBeamSpell |
graph TD;
A–>B;
A–>C;
B–>D;
UI MVC架构
1 | 需要的代码 |
- HUD
- ViewModel MVVM
- Widget 控件基类
- WidgetController 小部件控制
类
Ability System 技能管理
| AuraSummonAbility | 怪物召唤 |
| ProjectileSpell | 投射物 |
| UAuraBeamSpell | 光束 |
| Electrocute:继承UArcaneShards | 雷电技能 |
| UArcaneShards | 水晶碎片 |
| UAuraFireBlast | 多火球 |
| UAuraFireBolt:继承投射物ProjectileSpell | 火球 |
| UAuraGameplayAbility | 基类 |
| UAuraPassiveAbility | 被动 |
| UAuraDamageGameplayAbility | 处理伤害 |
Actor 技能实例
| AuraEffectActor | 火焰 | |
| AuraEnemySpawnPoint | 敌人生成 | |
| Enemy Spawn Volume | 敌人生成 | |
| Fire Ball | 火球 | |
| AuraProjectile | 弹 | |
| Magic Circle | 魔术圈 | |
| Point Collection | 点集合 | |
蓝图
ACS配置
1 | // Copyright Epic Games, Inc. All Rights Reserved. |
属性配置
UAttributeSet配置
showdebug abilitysystem 显示属性
1 | // Fill out your copyright notice in the Description page of Project Settings. |
1 | // Fill out your copyright notice in the Description page of Project Settings. |
PlayerState配置
1 |
|
1 |
|
玩家配置
- 基类
1 |
|
1 | UAbilitySystemComponent* AAuraCharacterBase::GetAbilitySystemComponent() const |
- 子类
1 |
|
1 |
|
添加和删除
- 添加
1 | AbilitySystemComponent->SpawnedAttributes.AddUnique(WeaponAttributeSetPointer); |
- 删除
1 | AbilitySystemComponent->SpawnedAttributes.Remove(WeaponAttributeSetPointer); |
能力(Ability)
GA一般要做的事
设置GA的Tag、CD、Cost等属性。
获取必要信息,主要通过Get Actor Info。如果是通过Event调用的GA(使用Activate Ability From Event节点作为输入),还可以通过Gameplay Event Data获取。
编写逻辑,如播放动画、应用GE、应用冲量等。
一定不要忘了EndAbility。
标签(Tags)
- 能力标签(Ability Tags)
- 取消带标签的能力(Cancel abilities with tag)
- 锁定带标签的能力(vlock [应为“lock”的误写] abilities with tag)
- 激活拥有的标签(activation owned tags)
- 激活被阻止的标签(activation blocked tags)
- 源所需标签(source required tags)
- 源被阻止的标签(source blocked tags)
- 目标所需标签(target required tags)
- 目标被阻止的标签(target blocked tags)
输入(Input)
- 直接复制输入(Replicate Input Directly)
高级(Advanced)
- 复制策略(ReplicationPolicy)
- 实例化策略(Instancing Policy)
- 服务器尊重远程能力取消(Server Respects Remote Ability Cancellation)
- 重新触发实例化能力(Retrigger Instanced Ability)
- 网络执行策略(Net Execution Policy)
- 网络安全策略(Net Security Policy)
成本(Costs)
- 成本游戏效果类(Cost Gameplay Effect Class)
触发器(Triggers)
- 能力触发器(Ability Triggers)
冷却时间(Cooldowns)
- 冷却时间游戏效果类(Cooldown Gameplay Effect Class)
申请GE实现扣血
1 | applygameplayeffecttoowner |
GE
- 编辑器状态文本 (Editor Status Text)
- 持续时间 (Duration)
- Instant 立即生效
- Infinite 永久生效
- Period 周期内生效
- 游戏效果 (Gameplay Effect)
- 组件 (Components)
- 修饰符 (Modifiers)
- 执行 (Executions)
- 游戏提示 (Gameplay Cues)
- Require Modifier Success to Trigger Cues 需要修饰符成功才能触发提示
- Suppress Stacking Cues 抑制叠加提示
- Gameplay Cues 游戏提示
- 叠加 (Stacking)
- Stacking Type 叠加类型
蓝图文件夹
AbilitySystem 能力系统
- 定义能力系统,包括GE,GA,GC和属性数据
Aura
- Abilities 能力 里边的蓝图好像是魔法阵的
- Effects 效果 用于初始化数据的GE类






































