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,509 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ue-actor-component-architecture
|
|
3
|
+
description: "Actor and component design — BeginPlay, Tick, component attachment, ownership, child actors"
|
|
4
|
+
category: "gamedev"
|
|
5
|
+
argument-hint: "[actor o component]"
|
|
6
|
+
user-invocable: true
|
|
7
|
+
allowed-tools: Read, Glob, Grep, Bash, Write, Edit
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# UE Actor-Component Architecture
|
|
11
|
+
|
|
12
|
+
You are an expert in Unreal Engine's Actor-Component architecture.
|
|
13
|
+
|
|
14
|
+
Ask before writing: this skill edits actor and component classes under `Source/`. Propose the change and get approval before using Write or Edit.
|
|
15
|
+
|
|
16
|
+
## Project Context
|
|
17
|
+
|
|
18
|
+
Before responding, read `docs/unreal/project-context.md` for the project's subsystem inventory, coding conventions, and any existing actor hierarchies or component patterns. This tells you which base classes are established and what naming conventions apply.
|
|
19
|
+
|
|
20
|
+
## Information Gathering
|
|
21
|
+
|
|
22
|
+
Clarify the developer's specific need before diving in:
|
|
23
|
+
|
|
24
|
+
- New actor from scratch, or adding behavior to an existing one?
|
|
25
|
+
- Logic-only (UActorComponent) or needs world position (USceneComponent)?
|
|
26
|
+
- Spawning requirement (deferred init, pooling, net-spawned)?
|
|
27
|
+
- Lifecycle bug (BeginPlay/Constructor confusion, component not initialized)?
|
|
28
|
+
- Cross-actor behavior via interfaces?
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Core Architecture Mental Model
|
|
33
|
+
|
|
34
|
+
Unreal's Actor-Component system is **composition over inheritance**. An `AActor` is a container that owns components. Behavior, rendering, collision, and logic are all expressed through `UActorComponent` subclasses.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
UObject
|
|
38
|
+
└── AActor (placeable/spawnable world entity)
|
|
39
|
+
└── owns N x UActorComponent (reusable behavior units)
|
|
40
|
+
└── USceneComponent (adds transform + attachment)
|
|
41
|
+
└── UPrimitiveComponent (adds collision + rendering)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`AActor` is a full `UObject` — never `new`/`delete` an actor. Always use `SpawnActor` and `Destroy`.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Actor Lifecycle
|
|
49
|
+
|
|
50
|
+
Full event order and safety rules are in `references/actor-lifecycle.md`. Key sequence:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Constructor → CreateDefaultSubobject, tick config, default values
|
|
54
|
+
PostActorCreated → spawned actors only; before construction script
|
|
55
|
+
PostInitializeComponents → all components initialized; world accessible
|
|
56
|
+
BeginPlay → game running; full logic OK; components BeginPlay fires here
|
|
57
|
+
Tick(DeltaTime) → per-frame; each ticking component's TickComponent fires
|
|
58
|
+
EndPlay(EEndPlayReason) → cleanup; ClearAllTimers; call Super
|
|
59
|
+
Destroyed → pre-GC; avoid complex logic
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Constructor vs BeginPlay
|
|
63
|
+
|
|
64
|
+
**Constructor** runs first on the **Class Default Object (CDO)** — an archetype used for default values. `GetWorld()` returns `nullptr` on the CDO. Never access the world or other actors in the constructor.
|
|
65
|
+
|
|
66
|
+
```cpp
|
|
67
|
+
// CORRECT — constructor-time only
|
|
68
|
+
AMyActor::AMyActor()
|
|
69
|
+
{
|
|
70
|
+
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
|
71
|
+
SetRootComponent(MeshComp);
|
|
72
|
+
PrimaryActorTick.bCanEverTick = true;
|
|
73
|
+
PrimaryActorTick.TickInterval = 0.1f;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// CORRECT — world-dependent code belongs in BeginPlay
|
|
77
|
+
void AMyActor::BeginPlay()
|
|
78
|
+
{
|
|
79
|
+
Super::BeginPlay(); // Required — always call Super
|
|
80
|
+
GetWorld()->SpawnActor<AProjectile>(...);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### PostInitializeComponents
|
|
85
|
+
|
|
86
|
+
Called before BeginPlay; components are initialized; world exists. Use it to bind delegates to own components.
|
|
87
|
+
|
|
88
|
+
```cpp
|
|
89
|
+
void AMyCharacter::PostInitializeComponents()
|
|
90
|
+
{
|
|
91
|
+
Super::PostInitializeComponents();
|
|
92
|
+
HealthComponent->OnDeath.AddDynamic(this, &AMyCharacter::HandleDeath);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### EndPlay — reasons matter
|
|
97
|
+
|
|
98
|
+
| Reason | When |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `Destroyed` | `Actor->Destroy()` called explicitly |
|
|
101
|
+
| `LevelTransition` | Map change |
|
|
102
|
+
| `EndPlayInEditor` | PIE session ended |
|
|
103
|
+
| `RemovedFromWorld` | Level streaming unloaded the sublevel |
|
|
104
|
+
| `Quit` | Application shutdown |
|
|
105
|
+
|
|
106
|
+
```cpp
|
|
107
|
+
void AMyActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
|
108
|
+
{
|
|
109
|
+
GetWorld()->GetTimerManager().ClearAllTimersForObject(this);
|
|
110
|
+
Super::EndPlay(EndPlayReason);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Network lifecycle note
|
|
115
|
+
|
|
116
|
+
**Replicated actors**: on clients, `BeginPlay` may fire before all replicated properties arrive. Use `OnRep_` callbacks for initialization that depends on replicated state. `PostNetReceive()` fires after each replication update (including the initial one); guard one-time setup inside it with a `bHasInitialized` flag. `PostNetInit` is not a standard `AActor` virtual and should not be used as a general init hook.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Component System
|
|
121
|
+
|
|
122
|
+
### The three layers
|
|
123
|
+
|
|
124
|
+
| Class | Transform | Rendering/Collision | Use for |
|
|
125
|
+
|---|---|---|---|
|
|
126
|
+
| `UActorComponent` | No | No | Pure logic — health, inventory, AI data |
|
|
127
|
+
| `USceneComponent` | Yes | No | Transform anchors, grouping, pivot points |
|
|
128
|
+
| `UPrimitiveComponent` | Yes | Yes | Meshes, shapes, anything visible or collidable |
|
|
129
|
+
|
|
130
|
+
**Notable subclasses**: `UStaticMeshComponent`, `USkeletalMeshComponent`, shape primitives (`UCapsuleComponent`, `UBoxComponent`, `USphereComponent`), `UWidgetComponent` (3D UI in world space — requires `"UMG"` module), `USpringArmComponent` + `UCameraComponent`, `UChildActorComponent`. See `references/component-types.md`.
|
|
131
|
+
|
|
132
|
+
### Component creation
|
|
133
|
+
|
|
134
|
+
**In the constructor** (for default components that appear in the Details panel):
|
|
135
|
+
|
|
136
|
+
```cpp
|
|
137
|
+
AMyActor::AMyActor()
|
|
138
|
+
{
|
|
139
|
+
// CreateDefaultSubobject registers the component as a subobject —
|
|
140
|
+
// it is serialized with the actor and visible in Blueprint editors.
|
|
141
|
+
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
|
142
|
+
SetRootComponent(MeshComp);
|
|
143
|
+
|
|
144
|
+
ArrowComp = CreateDefaultSubobject<UArrowComponent>(TEXT("Arrow"));
|
|
145
|
+
ArrowComp->SetupAttachment(MeshComp); // Parent set here; no world needed
|
|
146
|
+
|
|
147
|
+
HealthComp = CreateDefaultSubobject<UHealthComponent>(TEXT("Health"));
|
|
148
|
+
// Logic-only components need no attachment
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**At runtime** (dynamic addition):
|
|
153
|
+
|
|
154
|
+
```cpp
|
|
155
|
+
void AMyActor::AddLight()
|
|
156
|
+
{
|
|
157
|
+
// NewObject creates but does NOT register with the world
|
|
158
|
+
UPointLightComponent* Light = NewObject<UPointLightComponent>(this,
|
|
159
|
+
UPointLightComponent::StaticClass(), TEXT("DynamicLight"));
|
|
160
|
+
|
|
161
|
+
Light->SetupAttachment(GetRootComponent());
|
|
162
|
+
Light->RegisterComponent(); // Gives it world presence (render proxy, physics)
|
|
163
|
+
Light->SetIntensity(5000.f);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
void AMyActor::RemoveLight(UActorComponent* Comp)
|
|
167
|
+
{
|
|
168
|
+
Comp->DestroyComponent(); // Unregisters and marks for GC
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// UnregisterComponent() removes a component from the world without destroying it (reversible).
|
|
172
|
+
// DestroyComponent() marks it for GC — irreversible. Use Unregister when you may re-enable it later.
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Why this distinction matters: constructor-created components are owned subobjects and participate in the actor's GC root. Runtime components via `NewObject` are not automatically serialized unless you add them to a `UPROPERTY` array.
|
|
176
|
+
|
|
177
|
+
### Attachment
|
|
178
|
+
|
|
179
|
+
```cpp
|
|
180
|
+
// Constructor (SetupAttachment — no world required)
|
|
181
|
+
SpringArmComp->SetupAttachment(RootComponent);
|
|
182
|
+
CameraComp->SetupAttachment(SpringArmComp);
|
|
183
|
+
|
|
184
|
+
// Runtime (AttachToComponent — world must exist)
|
|
185
|
+
WeaponMesh->AttachToComponent(
|
|
186
|
+
CharMesh,
|
|
187
|
+
FAttachmentTransformRules::SnapToTargetNotIncludingScale,
|
|
188
|
+
TEXT("WeaponSocket") // Named socket on the skeletal mesh
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
WeaponMesh->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Activation
|
|
195
|
+
|
|
196
|
+
```cpp
|
|
197
|
+
// In constructor — opt out of auto-activation for optional components
|
|
198
|
+
SoundComp->bAutoActivate = false;
|
|
199
|
+
|
|
200
|
+
// Runtime — Activate() checks ShouldActivate() internally
|
|
201
|
+
SoundComp->Activate();
|
|
202
|
+
SoundComp->Deactivate();
|
|
203
|
+
SoundComp->SetActive(true, /*bReset=*/false);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Spawning
|
|
209
|
+
|
|
210
|
+
### Standard spawn
|
|
211
|
+
|
|
212
|
+
```cpp
|
|
213
|
+
FActorSpawnParameters Params;
|
|
214
|
+
Params.Owner = this;
|
|
215
|
+
Params.Instigator = GetInstigator();
|
|
216
|
+
Params.SpawnCollisionHandlingOverride =
|
|
217
|
+
ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
|
218
|
+
Params.Name = FName("Enemy_Boss"); // deterministic name for replication (must be unique)
|
|
219
|
+
|
|
220
|
+
AEnemy* Enemy = GetWorld()->SpawnActor<AEnemy>(
|
|
221
|
+
AEnemy::StaticClass(), Location, Rotation, Params);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Deferred spawning — configure before BeginPlay
|
|
225
|
+
|
|
226
|
+
Use when the actor's `BeginPlay` reads data that must be set before it runs.
|
|
227
|
+
|
|
228
|
+
```cpp
|
|
229
|
+
AEnemy* Enemy = GetWorld()->SpawnActorDeferred<AEnemy>(
|
|
230
|
+
AEnemy::StaticClass(), SpawnTransform, Owner, Instigator,
|
|
231
|
+
ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
|
|
232
|
+
|
|
233
|
+
if (Enemy)
|
|
234
|
+
{
|
|
235
|
+
Enemy->SetEnemyData(EnemyDataAsset); // Set BEFORE BeginPlay
|
|
236
|
+
Enemy->FinishSpawning(SpawnTransform);
|
|
237
|
+
// FinishSpawning triggers PostInitializeComponents then BeginPlay
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Object pooling
|
|
242
|
+
|
|
243
|
+
For high-frequency actors (projectiles, shell casings), repeated `SpawnActor`/`Destroy` creates GC pressure. Pool them: pre-spawn, hide + disable collision to "return," re-enable to "reuse."
|
|
244
|
+
|
|
245
|
+
```cpp
|
|
246
|
+
AProjectile* AProjectilePool::Get()
|
|
247
|
+
{
|
|
248
|
+
for (AProjectile* P : Pool)
|
|
249
|
+
{
|
|
250
|
+
// IsHidden() reflects the pool's "inactive" state set on return.
|
|
251
|
+
// IsActive() exists only on UActorComponent, not on AActor.
|
|
252
|
+
if (P->IsHidden())
|
|
253
|
+
{
|
|
254
|
+
P->SetActorHiddenInGame(false);
|
|
255
|
+
P->SetActorEnableCollision(true);
|
|
256
|
+
return P;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
AProjectile* New = GetWorld()->SpawnActor<AProjectile>(ProjectileClass, ...);
|
|
260
|
+
Pool.Add(New);
|
|
261
|
+
return New;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Ticking
|
|
268
|
+
|
|
269
|
+
### Setup
|
|
270
|
+
|
|
271
|
+
```cpp
|
|
272
|
+
AMyActor::AMyActor()
|
|
273
|
+
{
|
|
274
|
+
PrimaryActorTick.bCanEverTick = true;
|
|
275
|
+
PrimaryActorTick.bStartWithTickEnabled = false; // Enable in BeginPlay
|
|
276
|
+
PrimaryActorTick.TickInterval = 0.1f; // ~10 Hz throttle
|
|
277
|
+
PrimaryActorTick.TickGroup = TG_PostPhysics; // After physics settles
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Tick groups: `TG_PrePhysics` (default, input/movement) → `TG_DuringPhysics` (physics-coupled logic, runs during physics step) → `TG_PostPhysics` (camera, IK) → `TG_PostUpdateWork` (final reads).
|
|
282
|
+
|
|
283
|
+
**Component tick**: Set `PrimaryComponentTick.bCanEverTick = true` in the component constructor, with `PrimaryComponentTick.TickGroup` for ordering — same API as actor tick.
|
|
284
|
+
|
|
285
|
+
### Tick dependencies
|
|
286
|
+
|
|
287
|
+
```cpp
|
|
288
|
+
// ActorA ticks after ActorB completes
|
|
289
|
+
ActorA->AddTickPrerequisiteActor(ActorB);
|
|
290
|
+
ComponentA->AddTickPrerequisiteComponent(ComponentB);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### When NOT to tick
|
|
294
|
+
|
|
295
|
+
Tick has per-frame cost even when nothing changes. Prefer:
|
|
296
|
+
|
|
297
|
+
```cpp
|
|
298
|
+
// Delayed/repeating events → FTimerHandle
|
|
299
|
+
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this,
|
|
300
|
+
&AMyActor::OnTimerFired, 2.0f, /*bLoop=*/true);
|
|
301
|
+
|
|
302
|
+
// State changes → delegates / multicast delegates
|
|
303
|
+
HealthComp->OnDeath.AddDynamic(this, &AMyActor::HandleDeath);
|
|
304
|
+
|
|
305
|
+
// Collision events → OnComponentBeginOverlap / OnActorBeginOverlap
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Only tick for true per-frame needs: smooth interpolation, physics sub-stepping, streaming queries.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Interfaces (UINTERFACE Pattern)
|
|
313
|
+
|
|
314
|
+
Interfaces let unrelated actor types respond to the same message without coupling through inheritance. This replaces `Cast<ASpecificType>` scattered across your codebase.
|
|
315
|
+
|
|
316
|
+
### Declaration
|
|
317
|
+
|
|
318
|
+
```cpp
|
|
319
|
+
// IInteractable.h
|
|
320
|
+
UINTERFACE(MinimalAPI, Blueprintable)
|
|
321
|
+
class UInteractable : public UInterface { GENERATED_BODY() };
|
|
322
|
+
|
|
323
|
+
class MYGAME_API IInteractable
|
|
324
|
+
{
|
|
325
|
+
GENERATED_BODY()
|
|
326
|
+
public:
|
|
327
|
+
// BlueprintNativeEvent: C++ default + Blueprint can override
|
|
328
|
+
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="Interaction")
|
|
329
|
+
void OnInteract(AActor* Instigator);
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Implementation
|
|
334
|
+
|
|
335
|
+
```cpp
|
|
336
|
+
// AChest.h
|
|
337
|
+
UCLASS()
|
|
338
|
+
class AChest : public AActor, public IInteractable
|
|
339
|
+
{
|
|
340
|
+
GENERATED_BODY()
|
|
341
|
+
public:
|
|
342
|
+
virtual void OnInteract_Implementation(AActor* Instigator) override;
|
|
343
|
+
};
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Calling through the interface
|
|
347
|
+
|
|
348
|
+
```cpp
|
|
349
|
+
// No cast needed — works on any actor or component
|
|
350
|
+
if (Target->Implements<UInteractable>())
|
|
351
|
+
{
|
|
352
|
+
// Execute_ prefix required for Blueprint-callable interface functions
|
|
353
|
+
IInteractable::Execute_OnInteract(Target, GetPawn());
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**Interface vs component**: use an interface for a *capability declaration* ("this can be interacted with") especially when Blueprint classes need to implement it. Use a component when the behavior has its own state, needs ticking, or is reused identically by many actor types.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Composition Patterns
|
|
362
|
+
|
|
363
|
+
### Favor components over deep inheritance
|
|
364
|
+
|
|
365
|
+
```cpp
|
|
366
|
+
// Wrong: inheritance hierarchy collapses under varied requirements
|
|
367
|
+
ACharacter → AHero → ASwordHero → AFireSwordHero
|
|
368
|
+
|
|
369
|
+
// Right: flat base + composed components
|
|
370
|
+
ABaseCharacter
|
|
371
|
+
+ UHealthComponent (HP, damage, death event)
|
|
372
|
+
+ UInventoryComponent (items, equipment)
|
|
373
|
+
+ UAbilityComponent (skill execution)
|
|
374
|
+
+ UStatusComponent (buffs/debuffs)
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Component-to-component communication
|
|
378
|
+
|
|
379
|
+
Components should not hold raw pointers to siblings. Query through the owner or use delegates:
|
|
380
|
+
|
|
381
|
+
```cpp
|
|
382
|
+
// Query approach
|
|
383
|
+
UHealthComponent* Health = GetOwner()->FindComponentByClass<UHealthComponent>();
|
|
384
|
+
|
|
385
|
+
// Delegate approach — total decoupling
|
|
386
|
+
HealthComp->OnDeath.AddDynamic(AbilityComp, &UAbilityComponent::OnOwnerDied);
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Data-driven composition
|
|
390
|
+
|
|
391
|
+
```cpp
|
|
392
|
+
// UEnemyData (UDataAsset) — varies per enemy type
|
|
393
|
+
// AEnemy reads configuration at BeginPlay or via SpawnActorDeferred
|
|
394
|
+
|
|
395
|
+
void AEnemy::Initialize(UEnemyData* Data)
|
|
396
|
+
{
|
|
397
|
+
HealthComp->SetMaxHealth(Data->MaxHealth);
|
|
398
|
+
|
|
399
|
+
for (TSubclassOf<UActorComponent> CompClass : Data->AdditionalComponents)
|
|
400
|
+
{
|
|
401
|
+
UActorComponent* Comp = NewObject<UActorComponent>(this, CompClass);
|
|
402
|
+
Comp->RegisterComponent();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Common Mistakes and Anti-Patterns
|
|
410
|
+
|
|
411
|
+
### Inheritance abuse
|
|
412
|
+
|
|
413
|
+
```cpp
|
|
414
|
+
// Wrong — one class per variant
|
|
415
|
+
UCLASS() class AFireEnemy : public AEnemy { };
|
|
416
|
+
UCLASS() class AIceEnemy : public AEnemy { };
|
|
417
|
+
|
|
418
|
+
// Right — one class, multiple DataAssets
|
|
419
|
+
// UEnemyData_Fire.uasset, UEnemyData_Ice.uasset → AEnemy reads at BeginPlay
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Tick polling instead of events
|
|
423
|
+
|
|
424
|
+
```cpp
|
|
425
|
+
// Wrong — checked every frame
|
|
426
|
+
void AMyActor::Tick(float DeltaTime)
|
|
427
|
+
{
|
|
428
|
+
if (HealthComp->IsDead()) { HandleDeath(); }
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Right — event-driven, zero per-frame cost
|
|
432
|
+
void AMyActor::BeginPlay()
|
|
433
|
+
{
|
|
434
|
+
Super::BeginPlay();
|
|
435
|
+
HealthComp->OnDeath.AddDynamic(this, &AMyActor::HandleDeath);
|
|
436
|
+
SetActorTickEnabled(false);
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Forgetting Super in lifecycle overrides
|
|
441
|
+
|
|
442
|
+
Every lifecycle override must call `Super::`. Skipping it breaks replication, GC, and Blueprint event forwarding.
|
|
443
|
+
|
|
444
|
+
```cpp
|
|
445
|
+
// Always
|
|
446
|
+
void AMyActor::BeginPlay() { Super::BeginPlay(); ... }
|
|
447
|
+
void AMyActor::EndPlay(...) { ...; Super::EndPlay(EndPlayReason); }
|
|
448
|
+
void AMyActor::PostInitializeComponents() { Super::PostInitializeComponents(); ... }
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Storing raw actor pointers
|
|
452
|
+
|
|
453
|
+
```cpp
|
|
454
|
+
// Wrong — crashes when the actor is destroyed
|
|
455
|
+
AActor* CachedTarget;
|
|
456
|
+
|
|
457
|
+
// Right — use TWeakObjectPtr and check IsValid before use
|
|
458
|
+
TWeakObjectPtr<AActor> CachedTarget;
|
|
459
|
+
if (CachedTarget.IsValid()) { CachedTarget->DoSomething(); }
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Related Skills
|
|
465
|
+
|
|
466
|
+
- `/ue-cpp-foundations` — UCLASS, UPROPERTY, UFUNCTION macros underpinning all patterns above
|
|
467
|
+
- `/ue-gameplay-framework` — GameMode, PlayerController, Pawn layered on top of this system
|
|
468
|
+
- `/ue-physics-collision` — UPrimitiveComponent channels, sweeps, overlap events
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
## Quick Reference
|
|
473
|
+
|
|
474
|
+
```
|
|
475
|
+
Constructor CreateDefaultSubobject, SetRootComponent, tick config
|
|
476
|
+
PostInitialize Bind delegates to own components; world accessible
|
|
477
|
+
BeginPlay Full game logic; SpawnActor; timer setup
|
|
478
|
+
Tick Per-frame only; prefer timers/events
|
|
479
|
+
EndPlay ClearAllTimers; Super required
|
|
480
|
+
Destroyed Pre-GC; minimal logic
|
|
481
|
+
|
|
482
|
+
CreateDefaultSubobject<T>() Constructor — owned, serialized, editable
|
|
483
|
+
NewObject<T>() + RegisterComponent() Runtime — dynamic, not auto-serialized
|
|
484
|
+
SetupAttachment() Constructor parent declaration
|
|
485
|
+
AttachToComponent() Runtime attachment with transform rules
|
|
486
|
+
|
|
487
|
+
SpawnActor<T>() Standard spawn
|
|
488
|
+
SpawnActorDeferred<T>() + Finish Configure before BeginPlay fires
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
## Checklist
|
|
494
|
+
|
|
495
|
+
Validate before considering the work done:
|
|
496
|
+
|
|
497
|
+
- [ ] Tick is disabled unless genuinely needed; timers or events used instead
|
|
498
|
+
- [ ] Ownership and attachment are explicit, with no dangling component references
|
|
499
|
+
- [ ] Initialization happens in the correct lifecycle stage, not all in `BeginPlay`
|
|
500
|
+
- [ ] Conventions in `docs/unreal/project-context.md` were read and followed
|
|
501
|
+
- [ ] The Common Mistakes section of this skill was reviewed against the change
|
|
502
|
+
|
|
503
|
+
**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.
|
|
504
|
+
|
|
505
|
+
## Next Steps
|
|
506
|
+
|
|
507
|
+
- `/ue-gameplay-framework` — wire the actors into the framework classes
|
|
508
|
+
- `/code-review` — architectural and quality review of the change
|
|
509
|
+
- `/commit` — conventional commit once the change is verified
|