claude-code-arcane 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +54 -6
- package/agents/game/ue-blueprint-specialist.md +125 -0
- package/agents/game/ue-gas-specialist.md +133 -0
- package/agents/game/ue-umg-specialist.md +131 -0
- package/dist/cli.js +5 -0
- package/docs/SKILLS-CATALOG.md +42 -3
- package/docs/USER-GUIDE.md +2 -2
- package/hooks/detect-unreal.sh +90 -0
- package/package.json +1 -1
- package/profiles/unreal-dev.yaml +97 -0
- package/rules/gamedev/unreal-code.md +125 -0
- package/skills/install-mcp/SKILL.md +135 -46
- package/skills/install-mcp/references/unreal-operations.md +55 -0
- package/skills/ue-actor-component-architecture/SKILL.md +509 -0
- package/skills/ue-actor-component-architecture/references/actor-lifecycle.md +301 -0
- package/skills/ue-actor-component-architecture/references/component-types.md +592 -0
- package/skills/ue-ai-navigation/SKILL.md +526 -0
- package/skills/ue-ai-navigation/references/behavior-tree-patterns.md +392 -0
- package/skills/ue-ai-navigation/references/behavior-tree-workflow.md +107 -0
- package/skills/ue-ai-navigation/references/custom-bttask.md +104 -0
- package/skills/ue-ai-navigation/references/eqs-reference.md +423 -0
- package/skills/ue-animation-system/SKILL.md +521 -0
- package/skills/ue-animation-system/references/anim-notify-reference.md +486 -0
- package/skills/ue-animation-system/references/locomotion-setup.md +550 -0
- package/skills/ue-async-threading/SKILL.md +433 -0
- package/skills/ue-async-threading/references/thread-safety-guide.md +213 -0
- package/skills/ue-async-threading/references/threading-patterns.md +345 -0
- package/skills/ue-audio-system/SKILL.md +527 -0
- package/skills/ue-audio-system/references/audio-setup-patterns.md +700 -0
- package/skills/ue-blueprints/SKILL.md +134 -0
- package/skills/ue-blueprints/references/communication.md +82 -0
- package/skills/ue-character-movement/SKILL.md +475 -0
- package/skills/ue-character-movement/references/cmc-extension-patterns.md +335 -0
- package/skills/ue-character-movement/references/movement-pipeline.md +189 -0
- package/skills/ue-cpp-foundations/SKILL.md +533 -0
- package/skills/ue-cpp-foundations/references/components-and-gc.md +107 -0
- package/skills/ue-cpp-foundations/references/container-patterns.md +544 -0
- package/skills/ue-cpp-foundations/references/delegate-patterns.md +497 -0
- package/skills/ue-cpp-foundations/references/gameplay-classes-cpp.md +136 -0
- package/skills/ue-cpp-foundations/references/property-specifiers.md +306 -0
- package/skills/ue-data-assets-tables/SKILL.md +527 -0
- package/skills/ue-data-assets-tables/references/asset-loading-patterns.md +306 -0
- package/skills/ue-data-assets-tables/references/data-driven-design.md +378 -0
- package/skills/ue-editor-tools/SKILL.md +523 -0
- package/skills/ue-editor-tools/references/detail-customization-patterns.md +395 -0
- package/skills/ue-editor-tools/references/editor-module-setup.md +480 -0
- package/skills/ue-game-features/SKILL.md +477 -0
- package/skills/ue-game-features/references/experience-system.md +222 -0
- package/skills/ue-game-features/references/game-feature-patterns.md +308 -0
- package/skills/ue-gameplay-abilities/SKILL.md +518 -0
- package/skills/ue-gameplay-abilities/references/ability-task-reference.md +391 -0
- package/skills/ue-gameplay-abilities/references/gameplay-effect-reference.md +397 -0
- package/skills/ue-gameplay-abilities/references/gas-setup-patterns.md +369 -0
- package/skills/ue-gameplay-framework/SKILL.md +466 -0
- package/skills/ue-gameplay-framework/references/framework-class-map.md +243 -0
- package/skills/ue-input-system/SKILL.md +394 -0
- package/skills/ue-input-system/references/cpp-setup.md +131 -0
- package/skills/ue-input-system/references/enhanced-input-workflow.md +117 -0
- package/skills/ue-input-system/references/input-action-reference.md +731 -0
- package/skills/ue-mass-entity/SKILL.md +476 -0
- package/skills/ue-mass-entity/references/mass-entity-patterns.md +319 -0
- package/skills/ue-mass-entity/references/mass-fragment-reference.md +119 -0
- package/skills/ue-materials-rendering/SKILL.md +526 -0
- package/skills/ue-materials-rendering/references/material-parameter-reference.md +216 -0
- package/skills/ue-materials-rendering/references/post-process-settings.md +383 -0
- package/skills/ue-module-build-system/SKILL.md +487 -0
- package/skills/ue-module-build-system/references/build-cs-reference.md +418 -0
- package/skills/ue-module-build-system/references/common-build-errors.md +381 -0
- package/skills/ue-naming-conventions/SKILL.md +142 -0
- package/skills/ue-naming-conventions/references/asset-name-modifiers.md +233 -0
- package/skills/ue-naming-conventions/references/content-structure.md +83 -0
- package/skills/ue-networking-replication/SKILL.md +452 -0
- package/skills/ue-networking-replication/references/replication-patterns.md +526 -0
- package/skills/ue-networking-replication/references/rpc-decision-guide.md +393 -0
- package/skills/ue-niagara-effects/SKILL.md +531 -0
- package/skills/ue-niagara-effects/references/niagara-data-interfaces.md +491 -0
- package/skills/ue-niagara-effects/references/niagara-parameter-types.md +153 -0
- package/skills/ue-niagara-effects/references/niagara-workflow.md +115 -0
- package/skills/ue-packaging/SKILL.md +116 -0
- package/skills/ue-physics-collision/SKILL.md +423 -0
- package/skills/ue-physics-collision/references/collision-channel-setup.md +218 -0
- package/skills/ue-physics-collision/references/trace-patterns.md +499 -0
- package/skills/ue-procedural-generation/SKILL.md +505 -0
- package/skills/ue-procedural-generation/references/pcg-node-reference.md +381 -0
- package/skills/ue-procedural-generation/references/procedural-mesh-patterns.md +940 -0
- package/skills/ue-project-context/SKILL.md +305 -0
- package/skills/ue-sequencer-cinematics/SKILL.md +506 -0
- package/skills/ue-sequencer-cinematics/references/sequencer-patterns.md +629 -0
- package/skills/ue-serialization-savegames/SKILL.md +524 -0
- package/skills/ue-serialization-savegames/references/save-system-architecture.md +705 -0
- package/skills/ue-state-trees/SKILL.md +489 -0
- package/skills/ue-state-trees/references/state-tree-mass-integration.md +184 -0
- package/skills/ue-state-trees/references/state-tree-patterns.md +321 -0
- package/skills/ue-testing-debugging/SKILL.md +520 -0
- package/skills/ue-testing-debugging/references/automation-test-patterns.md +387 -0
- package/skills/ue-testing-debugging/references/profiling-commands.md +357 -0
- package/skills/ue-ui-umg-slate/SKILL.md +431 -0
- package/skills/ue-ui-umg-slate/references/common-ui-setup.md +484 -0
- package/skills/ue-ui-umg-slate/references/widget-types.md +487 -0
- package/skills/ue-world-level-streaming/SKILL.md +518 -0
- package/skills/ue-world-level-streaming/references/streaming-patterns.md +414 -0
- package/templates/gamedev/unreal-project-context.md +107 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ue-gameplay-abilities
|
|
3
|
+
description: "GAS, Gameplay Abilities, Gameplay Effects, Attribute Sets, Gameplay Tags, Gameplay Cues"
|
|
4
|
+
category: "gamedev"
|
|
5
|
+
argument-hint: "[ability, effect o attribute]"
|
|
6
|
+
user-invocable: true
|
|
7
|
+
allowed-tools: Read, Glob, Grep, Bash, Write, Edit
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Gameplay Ability System (GAS)
|
|
11
|
+
|
|
12
|
+
You are an expert in Unreal Engine's Gameplay Ability System (GAS).
|
|
13
|
+
|
|
14
|
+
Ask before writing: this skill edits ability, effect and attribute set classes. Propose the change and get approval before using Write or Edit.
|
|
15
|
+
|
|
16
|
+
## Context Check
|
|
17
|
+
|
|
18
|
+
Before proceeding, read `docs/unreal/project-context.md` to determine:
|
|
19
|
+
- Whether the GameplayAbilities plugin is enabled
|
|
20
|
+
- Which actors own the AbilitySystemComponent (PlayerState vs Character)
|
|
21
|
+
- The replication mode in use (Minimal, Mixed, Full)
|
|
22
|
+
- Any existing AttributeSets or ability base classes
|
|
23
|
+
|
|
24
|
+
## Information Gathering
|
|
25
|
+
|
|
26
|
+
Ask the developer:
|
|
27
|
+
1. What type of abilities are needed? (active, passive, triggered, instant)
|
|
28
|
+
2. What attributes are required? (health, mana, stamina, custom stats)
|
|
29
|
+
3. Is this multiplayer? If so, which actors carry the ASC?
|
|
30
|
+
4. Are cooldowns and costs required, or is this a passive/trigger system?
|
|
31
|
+
5. Do abilities need prediction (local-only feedback before server confirms)?
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## GAS Architecture Overview
|
|
36
|
+
|
|
37
|
+
GAS has three pillars that live on `UAbilitySystemComponent` (ASC):
|
|
38
|
+
|
|
39
|
+
| Pillar | Class | Purpose |
|
|
40
|
+
|--------|-------|---------|
|
|
41
|
+
| Abilities | `UGameplayAbility` | Logic for what happens when activated |
|
|
42
|
+
| Effects | `UGameplayEffect` | Data-driven stat mutations (instant, duration, infinite) |
|
|
43
|
+
| Attributes | `UAttributeSet` | Float properties representing character stats |
|
|
44
|
+
|
|
45
|
+
GameplayTags thread through all three as requirements, grants, and blockers.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## GAS Setup
|
|
50
|
+
|
|
51
|
+
### 1. Enable the Plugin
|
|
52
|
+
|
|
53
|
+
Enable `GameplayAbilities` in `.uproject` Plugins array, then in `[ProjectName].Build.cs`:
|
|
54
|
+
```csharp
|
|
55
|
+
PublicDependencyModuleNames.AddRange(new string[]
|
|
56
|
+
{
|
|
57
|
+
"GameplayAbilities", "GameplayTags", "GameplayTasks"
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. AbilitySystemComponent Ownership
|
|
62
|
+
|
|
63
|
+
**PlayerState (recommended for multiplayer):** ASC persists across respawns because PlayerState
|
|
64
|
+
is not destroyed on death. Use this for player characters in networked games.
|
|
65
|
+
|
|
66
|
+
**Character/Pawn:** Simpler. Use for AI characters or single-player games where persistence
|
|
67
|
+
across respawns is not required.
|
|
68
|
+
|
|
69
|
+
See `references/gas-setup-patterns.md` for full initialization sequences for both patterns.
|
|
70
|
+
|
|
71
|
+
### 3. IAbilitySystemInterface
|
|
72
|
+
|
|
73
|
+
Every actor that owns or exposes an ASC must implement `IAbilitySystemInterface`:
|
|
74
|
+
|
|
75
|
+
```cpp
|
|
76
|
+
#include "AbilitySystemInterface.h"
|
|
77
|
+
|
|
78
|
+
UCLASS()
|
|
79
|
+
class AMyCharacter : public ACharacter, public IAbilitySystemInterface
|
|
80
|
+
{
|
|
81
|
+
GENERATED_BODY()
|
|
82
|
+
public:
|
|
83
|
+
virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override
|
|
84
|
+
{ return AbilitySystemComponent; }
|
|
85
|
+
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "GAS")
|
|
86
|
+
TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;
|
|
87
|
+
};
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Replication Modes
|
|
91
|
+
|
|
92
|
+
Set on the ASC after creation (server-side only):
|
|
93
|
+
|
|
94
|
+
```cpp
|
|
95
|
+
// In BeginPlay or PossessedBy on the server:
|
|
96
|
+
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
| Mode | When to Use |
|
|
100
|
+
|------|-------------|
|
|
101
|
+
| `Minimal` | AI or non-player actors; no GE replication to simulated proxies |
|
|
102
|
+
| `Mixed` | Player-controlled characters (owner gets full info, others get minimal) |
|
|
103
|
+
| `Full` | Non-player games or debugging; all GEs replicate to all clients |
|
|
104
|
+
|
|
105
|
+
### 5. InitAbilityActorInfo
|
|
106
|
+
|
|
107
|
+
Must be called on both server and client after possession. Call in `PossessedBy` (server)
|
|
108
|
+
and `OnRep_PlayerState` (client): `ASC->InitAbilityActorInfo(OwnerActor, AvatarActor)`.
|
|
109
|
+
See `references/gas-setup-patterns.md` for full dual-path code with respawn handling.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## GameplayAbilities
|
|
114
|
+
|
|
115
|
+
### Subclass UGameplayAbility
|
|
116
|
+
|
|
117
|
+
```cpp
|
|
118
|
+
#include "Abilities/GameplayAbility.h"
|
|
119
|
+
|
|
120
|
+
UCLASS()
|
|
121
|
+
class UMyFireballAbility : public UGameplayAbility
|
|
122
|
+
{
|
|
123
|
+
GENERATED_BODY()
|
|
124
|
+
public:
|
|
125
|
+
UMyFireballAbility();
|
|
126
|
+
virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle,
|
|
127
|
+
const FGameplayAbilityActorInfo* ActorInfo,
|
|
128
|
+
const FGameplayAbilityActivationInfo ActivationInfo,
|
|
129
|
+
const FGameplayEventData* TriggerEventData) override;
|
|
130
|
+
virtual void EndAbility(const FGameplayAbilitySpecHandle Handle,
|
|
131
|
+
const FGameplayAbilityActorInfo* ActorInfo,
|
|
132
|
+
const FGameplayAbilityActivationInfo ActivationInfo,
|
|
133
|
+
bool bReplicateEndAbility, bool bWasCancelled) override;
|
|
134
|
+
// Ability Tasks — async building blocks for latent abilities:
|
|
135
|
+
// UAbilityTask_WaitTargetData — waits for targeting (crosshair/AoE confirm)
|
|
136
|
+
// UAbilityTask_WaitGameplayEvent — waits for a GameplayEvent tag (e.g., anim notify)
|
|
137
|
+
// UAbilityTask_WaitDelay — simple timer
|
|
138
|
+
// UAbilityTask_PlayMontageAndWait — montage with callbacks (see ue-animation-system)
|
|
139
|
+
// See references/ability-task-reference.md for full list and custom task pattern.
|
|
140
|
+
// CancelAbility — called by CancelAbilitiesWithTag or ASC->CancelAbility(Handle)
|
|
141
|
+
// Internally calls EndAbility with bWasCancelled=true. Override to add cleanup:
|
|
142
|
+
virtual void CancelAbility(const FGameplayAbilitySpecHandle Handle,
|
|
143
|
+
const FGameplayAbilityActorInfo* ActorInfo,
|
|
144
|
+
const FGameplayAbilityActivationInfo ActivationInfo,
|
|
145
|
+
bool bReplicateCancelAbility) override;
|
|
146
|
+
// Custom activation guard — return false to block activation beyond tag checks
|
|
147
|
+
virtual bool CanActivateAbility(const FGameplayAbilitySpecHandle Handle,
|
|
148
|
+
const FGameplayAbilityActorInfo* ActorInfo, /*...*/) const override;
|
|
149
|
+
// Must call Super first. Add custom checks (resource availability, cooldown state).
|
|
150
|
+
protected:
|
|
151
|
+
UPROPERTY(EditDefaultsOnly, Category = "GAS")
|
|
152
|
+
TSubclassOf<UGameplayEffect> DamageEffect;
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### ActivateAbility Pattern
|
|
157
|
+
|
|
158
|
+
```cpp
|
|
159
|
+
void UMyFireballAbility::ActivateAbility(const FGameplayAbilitySpecHandle Handle,
|
|
160
|
+
const FGameplayAbilityActorInfo* ActorInfo,
|
|
161
|
+
const FGameplayAbilityActivationInfo ActivationInfo,
|
|
162
|
+
const FGameplayEventData* TriggerEventData)
|
|
163
|
+
{
|
|
164
|
+
// 1. Commit: validates and applies cost + cooldown
|
|
165
|
+
if (!CommitAbility(Handle, ActorInfo, ActivationInfo))
|
|
166
|
+
{
|
|
167
|
+
EndAbility(Handle, ActorInfo, ActivationInfo, true, true);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// 2. Apply effect / spawn projectile / etc.
|
|
171
|
+
FGameplayEffectSpecHandle Spec = MakeOutgoingGameplayEffectSpec(DamageEffect, GetAbilityLevel());
|
|
172
|
+
FGameplayAbilityTargetDataHandle TargetData =
|
|
173
|
+
UAbilitySystemBlueprintLibrary::AbilityTargetDataFromActor(
|
|
174
|
+
ActorInfo->AvatarActor.Get());
|
|
175
|
+
ApplyGameplayEffectSpecToTarget(Handle, ActorInfo, ActivationInfo, Spec, TargetData);
|
|
176
|
+
// 3. End (instant abilities end immediately; latent abilities wait for tasks)
|
|
177
|
+
EndAbility(Handle, ActorInfo, ActivationInfo, true, false);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`CommitAbility` is shorthand for `CommitAbilityCost` + `CommitAbilityCooldown`. Call them
|
|
182
|
+
separately when needed -- e.g., commit cost without starting cooldown for a channeled ability,
|
|
183
|
+
or commit cooldown without cost for a free ability.
|
|
184
|
+
|
|
185
|
+
### Instancing and Net Execution Policy
|
|
186
|
+
|
|
187
|
+
Set in the ability constructor:
|
|
188
|
+
|
|
189
|
+
```cpp
|
|
190
|
+
UMyFireballAbility::UMyFireballAbility()
|
|
191
|
+
{
|
|
192
|
+
// InstancedPerActor - one instance per actor; cheapest for persistent abilities
|
|
193
|
+
// InstancedPerExecution - new instance each activation; safe for concurrency
|
|
194
|
+
// NonInstanced - CDO runs the ability; no per-execution state
|
|
195
|
+
InstancingPolicy = EGameplayAbilityInstancingPolicy::InstancedPerActor;
|
|
196
|
+
|
|
197
|
+
// LocalPredicted - client runs immediately, server validates (player abilities)
|
|
198
|
+
// ServerOnly - authority only, no prediction
|
|
199
|
+
// LocalOnly - local client only (UI, cosmetic)
|
|
200
|
+
// ServerInitiated - server activates, clients run non-authoritative predicted copy
|
|
201
|
+
NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::LocalPredicted;
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Granting and Activating Abilities
|
|
206
|
+
|
|
207
|
+
```cpp
|
|
208
|
+
// Grant (server/authority only):
|
|
209
|
+
FGameplayAbilitySpecHandle Handle = ASC->GiveAbility(
|
|
210
|
+
FGameplayAbilitySpec(UMyFireballAbility::StaticClass(), 1 /*Level*/));
|
|
211
|
+
|
|
212
|
+
ASC->TryActivateAbility(Handle); // by handle
|
|
213
|
+
ASC->TryActivateAbilityByClass(UMyFireballAbility::StaticClass()); // by class
|
|
214
|
+
ASC->TryActivateAbilitiesByTag( // by tag
|
|
215
|
+
FGameplayTagContainer(FGameplayTag::RequestGameplayTag("Ability.Skill.Fireball")));
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Ability Tags
|
|
219
|
+
|
|
220
|
+
Configure in the ability CDO constructor:
|
|
221
|
+
|
|
222
|
+
```cpp
|
|
223
|
+
// Tags this ability grants to its owner while active:
|
|
224
|
+
ActivationOwnedTags.AddTag(FGameplayTag::RequestGameplayTag("Ability.Active.Casting"));
|
|
225
|
+
// Tags that prevent this ability from activating:
|
|
226
|
+
ActivationBlockedTags.AddTag(FGameplayTag::RequestGameplayTag("State.Stunned"));
|
|
227
|
+
// Cancel other active abilities with these tags on activation:
|
|
228
|
+
CancelAbilitiesWithTag.AddTag(FGameplayTag::RequestGameplayTag("Ability.Active.Melee"));
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## GameplayEffects
|
|
234
|
+
|
|
235
|
+
### Duration Policies
|
|
236
|
+
|
|
237
|
+
| Policy | Behavior |
|
|
238
|
+
|--------|----------|
|
|
239
|
+
| `Instant` | Executes once; modifies attribute base value permanently |
|
|
240
|
+
| `HasDuration` | Active for set duration; uses `DurationMagnitude` (seconds) |
|
|
241
|
+
| `Infinite` | Active until `RemoveActiveGameplayEffect` is called |
|
|
242
|
+
|
|
243
|
+
### Applying Effects
|
|
244
|
+
|
|
245
|
+
```cpp
|
|
246
|
+
FGameplayEffectContextHandle Ctx = ASC->MakeEffectContext();
|
|
247
|
+
FGameplayEffectSpecHandle Spec = ASC->MakeOutgoingSpec(UMyDamageEffect::StaticClass(), Level, Ctx);
|
|
248
|
+
|
|
249
|
+
// SetByCaller: inject runtime magnitude using a tag key
|
|
250
|
+
Spec.Data->SetSetByCallerMagnitude(
|
|
251
|
+
FGameplayTag::RequestGameplayTag("SetByCaller.Damage"), 75.f);
|
|
252
|
+
|
|
253
|
+
ASC->ApplyGameplayEffectSpecToSelf(*Spec.Data.Get()); // self
|
|
254
|
+
ASC->ApplyGameplayEffectSpecToTarget(*Spec.Data.Get(), TargetASC); // target
|
|
255
|
+
|
|
256
|
+
ASC->RemoveActiveGameplayEffect(ActiveHandle); // by handle
|
|
257
|
+
ASC->RemoveActiveGameplayEffectBySourceEffect(
|
|
258
|
+
UMyDamageEffect::StaticClass(), nullptr); // by class
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
See `references/gameplay-effect-reference.md` for stacking (AggregateBySource/AggregateByTarget),
|
|
262
|
+
periodic effects (damage over time), `UGameplayEffectExecutionCalculation` (complex modifier logic),
|
|
263
|
+
conditional effects, and immunity.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## AttributeSet
|
|
268
|
+
|
|
269
|
+
### Define Attributes
|
|
270
|
+
|
|
271
|
+
```cpp
|
|
272
|
+
// MyHealthSet.h
|
|
273
|
+
#include "AttributeSet.h"
|
|
274
|
+
#include "AbilitySystemComponent.h"
|
|
275
|
+
|
|
276
|
+
// Convenience macro - define in your project headers
|
|
277
|
+
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
|
|
278
|
+
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
|
|
279
|
+
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
|
|
280
|
+
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
|
|
281
|
+
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
|
|
282
|
+
|
|
283
|
+
UCLASS()
|
|
284
|
+
class UMyHealthSet : public UAttributeSet
|
|
285
|
+
{
|
|
286
|
+
GENERATED_BODY()
|
|
287
|
+
public:
|
|
288
|
+
UMyHealthSet();
|
|
289
|
+
|
|
290
|
+
// Called BEFORE any modification - use for clamping current value
|
|
291
|
+
virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;
|
|
292
|
+
|
|
293
|
+
// Called AFTER instant GE executes - react to changes (death, events)
|
|
294
|
+
virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;
|
|
295
|
+
|
|
296
|
+
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
|
297
|
+
|
|
298
|
+
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_Health, Category = "Health")
|
|
299
|
+
FGameplayAttributeData Health;
|
|
300
|
+
ATTRIBUTE_ACCESSORS(UMyHealthSet, Health)
|
|
301
|
+
|
|
302
|
+
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_MaxHealth, Category = "Health")
|
|
303
|
+
FGameplayAttributeData MaxHealth;
|
|
304
|
+
ATTRIBUTE_ACCESSORS(UMyHealthSet, MaxHealth)
|
|
305
|
+
|
|
306
|
+
protected:
|
|
307
|
+
UFUNCTION()
|
|
308
|
+
void OnRep_Health(const FGameplayAttributeData& OldHealth);
|
|
309
|
+
|
|
310
|
+
UFUNCTION()
|
|
311
|
+
void OnRep_MaxHealth(const FGameplayAttributeData& OldMaxHealth);
|
|
312
|
+
};
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
In the `.cpp`, implement replication and callbacks:
|
|
316
|
+
|
|
317
|
+
```cpp
|
|
318
|
+
void UMyHealthSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
319
|
+
{
|
|
320
|
+
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
321
|
+
DOREPLIFETIME_CONDITION_NOTIFY(UMyHealthSet, Health, COND_None, REPNOTIFY_Always);
|
|
322
|
+
DOREPLIFETIME_CONDITION_NOTIFY(UMyHealthSet, MaxHealth, COND_None, REPNOTIFY_Always);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
void UMyHealthSet::OnRep_Health(const FGameplayAttributeData& OldHealth)
|
|
326
|
+
{
|
|
327
|
+
GAMEPLAYATTRIBUTE_REPNOTIFY(UMyHealthSet, Health, OldHealth);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// PreAttributeChange: clamp CURRENT value before any modification
|
|
331
|
+
void UMyHealthSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
|
|
332
|
+
{
|
|
333
|
+
Super::PreAttributeChange(Attribute, NewValue);
|
|
334
|
+
if (Attribute == GetHealthAttribute())
|
|
335
|
+
NewValue = FMath::Clamp(NewValue, 0.f, GetMaxHealth());
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// PostGameplayEffectExecute: react AFTER instant GE modifies base value (damage, death)
|
|
339
|
+
void UMyHealthSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
|
|
340
|
+
{
|
|
341
|
+
Super::PostGameplayEffectExecute(Data);
|
|
342
|
+
if (Data.EvaluatedData.Attribute == GetHealthAttribute())
|
|
343
|
+
{
|
|
344
|
+
SetHealth(FMath::Clamp(GetHealth(), 0.f, GetMaxHealth()));
|
|
345
|
+
if (GetHealth() <= 0.f) { /* trigger death */ }
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Register AttributeSet on ASC
|
|
351
|
+
|
|
352
|
+
```cpp
|
|
353
|
+
// In PlayerState or Character constructor:
|
|
354
|
+
// Option 1: CreateDefaultSubobject (auto-registered as subobject)
|
|
355
|
+
HealthSet = CreateDefaultSubobject<UMyHealthSet>(TEXT("HealthSet"));
|
|
356
|
+
|
|
357
|
+
// Option 2: Runtime (authority only) — create and register as subobject:
|
|
358
|
+
UMyHealthSet* NewSet = NewObject<UMyHealthSet>(this);
|
|
359
|
+
AbilitySystemComponent->AddSpawnedAttribute(NewSet);
|
|
360
|
+
|
|
361
|
+
// Read attribute value:
|
|
362
|
+
float CurrentHealth = AbilitySystemComponent->GetNumericAttribute(
|
|
363
|
+
UMyHealthSet::GetHealthAttribute());
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**Multiple AttributeSets**: An ASC can host multiple `UAttributeSet` subclasses (e.g.,
|
|
367
|
+
`UHealthSet` + `UOffenseSet`), each auto-discovered via subobject enumeration. Never register
|
|
368
|
+
two instances of the same class -- the second is silently ignored.
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## GameplayTags
|
|
373
|
+
|
|
374
|
+
### Defining Tags
|
|
375
|
+
|
|
376
|
+
In `Config/DefaultGameplayTags.ini` or via native tags (preferred for code references):
|
|
377
|
+
|
|
378
|
+
```cpp
|
|
379
|
+
// MyGameplayTags.h
|
|
380
|
+
#include "NativeGameplayTags.h"
|
|
381
|
+
UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Ability_Fireball)
|
|
382
|
+
UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_State_Stunned)
|
|
383
|
+
|
|
384
|
+
// MyGameplayTags.cpp
|
|
385
|
+
UE_DEFINE_GAMEPLAY_TAG_COMMENT(TAG_Ability_Fireball, "Ability.Skill.Fireball", "Fireball ability")
|
|
386
|
+
UE_DEFINE_GAMEPLAY_TAG_COMMENT(TAG_State_Stunned, "State.Stunned", "Actor is stunned")
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Tag Matching
|
|
390
|
+
|
|
391
|
+
`"A.1".MatchesTag("A") == true` (hierarchical); `MatchesTagExact` requires exact match.
|
|
392
|
+
|
|
393
|
+
```cpp
|
|
394
|
+
FGameplayTagContainer Tags;
|
|
395
|
+
Tags.HasTag(FireballTag); // parent-aware match
|
|
396
|
+
Tags.HasTagExact(FireballTag); // exact only
|
|
397
|
+
Tags.HasAny(OtherContainer);
|
|
398
|
+
Tags.HasAll(OtherContainer);
|
|
399
|
+
|
|
400
|
+
// Query ASC:
|
|
401
|
+
ASC->HasMatchingGameplayTag(TAG_State_Stunned);
|
|
402
|
+
ASC->GetOwnedGameplayTags(); // FGameplayTagContainer
|
|
403
|
+
|
|
404
|
+
// Listen for changes:
|
|
405
|
+
ASC->RegisterGameplayTagEvent(TAG_State_Stunned, EGameplayTagEventType::NewOrRemoved)
|
|
406
|
+
.AddUObject(this, &AMyCharacter::OnStunnedTagChanged);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Loose Tags (Manual, No GE)
|
|
410
|
+
|
|
411
|
+
```cpp
|
|
412
|
+
ASC->AddLooseGameplayTag(TAG_State_Stunned);
|
|
413
|
+
ASC->RemoveLooseGameplayTag(TAG_State_Stunned);
|
|
414
|
+
// Loose tags are NOT replicated by default. To replicate a loose tag,
|
|
415
|
+
// pass EGameplayTagReplicationState::TagOnly as the third argument:
|
|
416
|
+
ASC->AddLooseGameplayTag(TAG_State_Buffed, 1, EGameplayTagReplicationState::TagOnly);
|
|
417
|
+
ASC->RemoveLooseGameplayTag(TAG_State_Buffed, 1, EGameplayTagReplicationState::TagOnly);
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## GameplayCues
|
|
423
|
+
|
|
424
|
+
Cosmetic-only (particles, sounds, decals). Never affect gameplay state. Tag prefix: `GameplayCue.`
|
|
425
|
+
|
|
426
|
+
In the GE asset, add `FGameplayEffectCue` entries with `GameplayCueTags` and level range.
|
|
427
|
+
|
|
428
|
+
```cpp
|
|
429
|
+
// Burst (one-shot):
|
|
430
|
+
ASC->ExecuteGameplayCue(FGameplayTag::RequestGameplayTag("GameplayCue.Hit.Fire"),
|
|
431
|
+
ASC->MakeEffectContext());
|
|
432
|
+
|
|
433
|
+
// Persistent (add/remove pair):
|
|
434
|
+
ASC->AddGameplayCue(FGameplayTag::RequestGameplayTag("GameplayCue.Buff.Speed"));
|
|
435
|
+
ASC->RemoveGameplayCue(FGameplayTag::RequestGameplayTag("GameplayCue.Buff.Speed"));
|
|
436
|
+
|
|
437
|
+
// Poll active state:
|
|
438
|
+
bool bActive = ASC->IsGameplayCueActive(FGameplayTag::RequestGameplayTag("GameplayCue.Buff.Speed"));
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Cue Notify classes:
|
|
442
|
+
- `AGameplayCueNotify_Actor`: Persistent/looping. Overrides `OnActive`, `WhileActive`, `OnRemove`.
|
|
443
|
+
- `AGameplayCueNotify_Static`: Burst/one-shot. Overrides `OnExecute`.
|
|
444
|
+
|
|
445
|
+
Place cue notify assets in `/Game/GAS/GameplayCues/` for `UGameplayCueManager` auto-discovery.
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## Common Mistakes and Anti-Patterns
|
|
450
|
+
|
|
451
|
+
**ASC ownership confusion:** Implement `IAbilitySystemInterface` on the class that *owns* the ASC
|
|
452
|
+
(PlayerState), not just on the Pawn. Otherwise `UAbilitySystemBlueprintLibrary` lookups fail.
|
|
453
|
+
|
|
454
|
+
**InitAbilityActorInfo only on server:** Clients need it too. Call in `OnRep_PlayerState` (client)
|
|
455
|
+
and `PossessedBy` (server). Skipping client-side init breaks attribute replication on the owning client.
|
|
456
|
+
|
|
457
|
+
**GEs applied before InitAbilityActorInfo:** The ASC is not ready; attributes are not registered.
|
|
458
|
+
Always complete init before granting abilities or applying effects.
|
|
459
|
+
|
|
460
|
+
**PreAttributeChange vs PostGameplayEffectExecute:** `PreAttributeChange` fires on every current-value
|
|
461
|
+
change (aggregator updates, buff adds/removes). Use it only to clamp. Use `PostGameplayEffectExecute`
|
|
462
|
+
to react to instant GE base-value execution (damage, death). Never send game events from `PreAttributeChange`.
|
|
463
|
+
|
|
464
|
+
**Forgetting CommitAbility:** Without it, the ability runs but consumes no mana and starts no cooldown.
|
|
465
|
+
|
|
466
|
+
**Loose tags not replicated:** `AddLooseGameplayTag` does not replicate by default. Pass
|
|
467
|
+
`EGameplayTagReplicationState::TagOnly` as the third argument to replicate the tag, or grant
|
|
468
|
+
via a GE for fully replicated effect-driven tags.
|
|
469
|
+
|
|
470
|
+
**Effect stacking overflow:** Stacks beyond `LimitCount` are silently rejected. Use `GetCurrentStackCount`
|
|
471
|
+
to inspect the current level before attempting further stack applications.
|
|
472
|
+
|
|
473
|
+
**GAS with AI:** AI has no PlayerState. Place the ASC on the AICharacter, call
|
|
474
|
+
`InitAbilityActorInfo(AICharacter, AICharacter)`, set replication mode to `Minimal`.
|
|
475
|
+
|
|
476
|
+
**Hot-joining**: Late-joining clients receive active effects via `FActiveGameplayEffectsContainer`
|
|
477
|
+
replication after `InitAbilityActorInfo`. Never apply startup GEs in `BeginPlay` unconditionally
|
|
478
|
+
-- server-only, or late joiners double-apply.
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Reference Files
|
|
483
|
+
|
|
484
|
+
- `references/gas-setup-patterns.md` — Full ASC ownership patterns and initialization sequences
|
|
485
|
+
for PlayerState and Character owners, multiplayer and single-player
|
|
486
|
+
- `references/gameplay-effect-reference.md` — Effect configuration, stacking rules, modifier
|
|
487
|
+
types, execution calculations, periodic effects, conditional effects
|
|
488
|
+
- `references/ability-task-reference.md` — Common built-in ability tasks and custom task patterns
|
|
489
|
+
|
|
490
|
+
## Related Skills
|
|
491
|
+
|
|
492
|
+
- `/ue-actor-component-architecture` — Component setup and subobject registration
|
|
493
|
+
- `/ue-networking-replication` — Replication modes, RPCs, prediction keys
|
|
494
|
+
- `/ue-animation-system` — Montage ability tasks (PlayMontageAndWait)
|
|
495
|
+
- `/ue-gameplay-framework` — PlayerState ownership pattern, Pawn/Controller lifecycle
|
|
496
|
+
- `/ue-cpp-foundations` — Delegate binding, UPROPERTY macros, TSubclassOf patterns
|
|
497
|
+
- `/ue-naming-conventions` — asset prefixes and Content folder layout for these assets
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## Checklist
|
|
502
|
+
|
|
503
|
+
Validate before considering the work done:
|
|
504
|
+
|
|
505
|
+
- [ ] Stats are modified through Gameplay Effects, never written directly
|
|
506
|
+
- [ ] State is identified by Gameplay Tags rather than booleans
|
|
507
|
+
- [ ] Ability activation policy and prediction were chosen deliberately
|
|
508
|
+
- [ ] Conventions in `docs/unreal/project-context.md` were read and followed
|
|
509
|
+
- [ ] The Common Mistakes section of this skill was reviewed against the change
|
|
510
|
+
|
|
511
|
+
**PASS** — every item holds. **CONCERNS** — the work stands but at least one item is unresolved and worth flagging to the user. **FAIL** — an item is violated in a way that breaks correctness, replication or the frame budget; fix it before handing the work over.
|
|
512
|
+
|
|
513
|
+
## Next Steps
|
|
514
|
+
|
|
515
|
+
- `/ue-networking-replication` — verify ability replication and prediction
|
|
516
|
+
- `/balance-check` — sanity-check the tuning values
|
|
517
|
+
- `/code-review` — architectural and quality review of the change
|
|
518
|
+
- `/commit` — conventional commit once the change is verified
|