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,475 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ue-character-movement
|
|
3
|
+
description: "CharacterMovementComponent, movement modes, root motion, network prediction"
|
|
4
|
+
category: "gamedev"
|
|
5
|
+
argument-hint: "[movement mode o feature]"
|
|
6
|
+
user-invocable: true
|
|
7
|
+
allowed-tools: Read, Glob, Grep, Bash, Write, Edit
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# UE Character Movement
|
|
11
|
+
|
|
12
|
+
You are an expert in Unreal Engine's `UCharacterMovementComponent` (CMC), the core system that drives character locomotion, floor detection, network prediction, and root motion integration. You understand the full Phys* pipeline, custom movement mode implementation, and the `FSavedMove_Character` prediction architecture.
|
|
13
|
+
|
|
14
|
+
Ask before writing: this skill edits CharacterMovementComponent subclasses and movement code. Propose the change and get approval before using Write or Edit.
|
|
15
|
+
|
|
16
|
+
## Context Check
|
|
17
|
+
|
|
18
|
+
Read `docs/unreal/project-context.md` to determine:
|
|
19
|
+
- Whether the project uses `ACharacter` or a custom pawn with its own movement
|
|
20
|
+
- The UE version (UE 5.4+ adds `GravityDirection` support, UE 5.5 changes `DoJump` signature)
|
|
21
|
+
- Whether multiplayer is involved (affects prediction pipeline complexity)
|
|
22
|
+
- Any existing CMC subclass or custom movement modes already in use
|
|
23
|
+
|
|
24
|
+
## Information Gathering
|
|
25
|
+
|
|
26
|
+
Ask the developer:
|
|
27
|
+
1. Are you extending `UCharacterMovementComponent` or configuring the default one?
|
|
28
|
+
2. Do you need custom movement modes (wall-running, climbing, dashing)?
|
|
29
|
+
3. Is this multiplayer? If so, do custom abilities need network prediction?
|
|
30
|
+
4. Are you integrating root motion from animations or gameplay code?
|
|
31
|
+
5. Do you need custom gravity directions (UE 5.4+)?
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## CMC Architecture
|
|
36
|
+
|
|
37
|
+
`UCharacterMovementComponent` sits at the end of a four-level class hierarchy:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
UMovementComponent
|
|
41
|
+
-> UNavMovementComponent
|
|
42
|
+
-> UPawnMovementComponent
|
|
43
|
+
-> UCharacterMovementComponent
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
CMC also implements `IRVOAvoidanceInterface` and `INetworkPredictionInterface`. It is declared `UCLASS(MinimalAPI)`.
|
|
47
|
+
|
|
48
|
+
CMC lives as a default subobject on `ACharacter`, created in the constructor. `ACharacter` provides the capsule, skeletal mesh, and high-level actions (`Jump`, `Crouch`, `LaunchCharacter`), while CMC handles the actual physics simulation, floor detection, and network prediction.
|
|
49
|
+
|
|
50
|
+
### Movement Modes
|
|
51
|
+
|
|
52
|
+
CMC dispatches movement logic through `EMovementMode`:
|
|
53
|
+
|
|
54
|
+
| Mode | Value | Description |
|
|
55
|
+
|------|-------|-------------|
|
|
56
|
+
| `MOVE_None` | 0 | No movement processing |
|
|
57
|
+
| `MOVE_Walking` | 1 | Ground movement with floor detection and step-up |
|
|
58
|
+
| `MOVE_NavWalking` | 2 | Walking driven by navmesh projection |
|
|
59
|
+
| `MOVE_Falling` | 3 | Airborne — gravity, air control, landing detection |
|
|
60
|
+
| `MOVE_Swimming` | 4 | Fluid movement with buoyancy |
|
|
61
|
+
| `MOVE_Flying` | 5 | Free 3D movement, no gravity |
|
|
62
|
+
| `MOVE_Custom` | 6 | User-defined; dispatches to `PhysCustom` with a `uint8` sub-mode |
|
|
63
|
+
| `MOVE_MAX` | 7 | Sentinel value |
|
|
64
|
+
|
|
65
|
+
Change modes with `SetMovementMode(EMovementMode, uint8 CustomMode = 0)`. The CMC calls `OnMovementModeChanged(PreviousMode, PreviousCustomMode)` after every transition, which is the correct place to handle enter/exit logic for custom modes.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Phys* Movement Pipeline
|
|
70
|
+
|
|
71
|
+
Every tick, CMC processes movement through a strict pipeline. Understanding this flow is essential for writing correct custom movement or debugging unexpected behavior.
|
|
72
|
+
|
|
73
|
+
`PerformMovement(float DeltaTime)` is the main entry point (protected). It calls `StartNewPhysics()`, which dispatches to the appropriate `Phys*` function based on the current `EMovementMode`. Each `Phys*` function is `protected virtual`:
|
|
74
|
+
|
|
75
|
+
- `PhysWalking(float deltaTime, int32 Iterations)` — ground movement
|
|
76
|
+
- `PhysNavWalking(float deltaTime, int32 Iterations)` — navmesh-projected walking
|
|
77
|
+
- `PhysFalling(float deltaTime, int32 Iterations)` — airborne/gravity
|
|
78
|
+
- `PhysSwimming(float deltaTime, int32 Iterations)` — fluid movement
|
|
79
|
+
- `PhysFlying(float deltaTime, int32 Iterations)` — free flight
|
|
80
|
+
- `PhysCustom(float deltaTime, int32 Iterations)` — your code here
|
|
81
|
+
|
|
82
|
+
Inside each `Phys*` function, two core methods do the heavy lifting:
|
|
83
|
+
|
|
84
|
+
**`CalcVelocity`** computes the velocity for this frame:
|
|
85
|
+
```cpp
|
|
86
|
+
// BlueprintCallable
|
|
87
|
+
void CalcVelocity(float DeltaTime, float Friction, bool bFluid, float BrakingDeceleration);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**`SafeMoveUpdatedComponent`** moves the capsule and resolves penetration:
|
|
91
|
+
```cpp
|
|
92
|
+
virtual bool SafeMoveUpdatedComponent(
|
|
93
|
+
const FVector& Delta,
|
|
94
|
+
const FQuat& NewRotation,
|
|
95
|
+
bool bSweep,
|
|
96
|
+
FHitResult& OutHit,
|
|
97
|
+
ETeleportType Teleport = ETeleportType::None
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
It wraps `MoveUpdatedComponent` and automatically handles depenetration if the move results in an overlap. Always prefer `SafeMoveUpdatedComponent` over `MoveUpdatedComponent` in custom Phys* functions.
|
|
102
|
+
|
|
103
|
+
When a sweep hits a surface, `SlideAlongSurface` projects movement along it. When hits occur in a corner (two blocking surfaces), CMC calls `TwoWallAdjust` (virtual on `UMovementComponent`) to compute a safe movement direction that avoids both walls. During `PhysWalking`, `ComputeGroundMovementDelta` (virtual) adjusts the velocity delta to follow the floor slope — it projects horizontal input onto the floor plane so the character walks along inclines rather than into them.
|
|
104
|
+
|
|
105
|
+
See `references/movement-pipeline.md` for the full flow diagram and per-mode breakdown.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Floor Detection
|
|
110
|
+
|
|
111
|
+
CMC's walking mode relies on continuous floor detection to determine whether the character is grounded.
|
|
112
|
+
|
|
113
|
+
### FFindFloorResult
|
|
114
|
+
|
|
115
|
+
```cpp
|
|
116
|
+
struct FFindFloorResult
|
|
117
|
+
{
|
|
118
|
+
uint32 bBlockingHit : 1; // Sweep hit something
|
|
119
|
+
uint32 bWalkableFloor : 1; // Hit surface passes walkability test
|
|
120
|
+
uint32 bLineTrace : 1; // Result came from line trace (not sweep)
|
|
121
|
+
float FloorDist; // Distance from capsule bottom to floor
|
|
122
|
+
float LineDist; // Distance from line trace
|
|
123
|
+
FHitResult HitResult; // Full hit result data
|
|
124
|
+
|
|
125
|
+
bool IsWalkableFloor() const { return bBlockingHit && bWalkableFloor; }
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Floor Detection Methods
|
|
130
|
+
|
|
131
|
+
`FindFloor` is the primary method:
|
|
132
|
+
```cpp
|
|
133
|
+
void FindFloor(
|
|
134
|
+
const FVector& CapsuleLocation,
|
|
135
|
+
FFindFloorResult& OutFloorResult,
|
|
136
|
+
bool bCanUseCachedLocation,
|
|
137
|
+
const FHitResult* DownwardSweepResult = nullptr
|
|
138
|
+
);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
It delegates to `ComputeFloorDist()`, which performs a downward capsule sweep followed by a line trace. The sweep finds the floor surface, and the line trace validates walkability at the exact contact point.
|
|
142
|
+
|
|
143
|
+
### Walkable Floor Angle
|
|
144
|
+
|
|
145
|
+
Two linked properties control what counts as "walkable":
|
|
146
|
+
|
|
147
|
+
- `WalkableFloorAngle` (default 44.765 degrees) — the maximum surface angle in degrees
|
|
148
|
+
- `WalkableFloorZ` — the corresponding Z component of the surface normal (auto-calculated from the angle)
|
|
149
|
+
|
|
150
|
+
Set the angle, not the Z value directly. `SetWalkableFloorAngle()` updates both.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Custom Movement Modes
|
|
155
|
+
|
|
156
|
+
`MOVE_Custom` with a `uint8` sub-mode is the standard way to add new movement types. This gives you up to 256 custom modes while reusing CMC's full network prediction pipeline.
|
|
157
|
+
|
|
158
|
+
### Implementation Steps
|
|
159
|
+
|
|
160
|
+
1. Define custom mode constants:
|
|
161
|
+
```cpp
|
|
162
|
+
UENUM(BlueprintType)
|
|
163
|
+
enum class ECustomMovementMode : uint8
|
|
164
|
+
{
|
|
165
|
+
WallRun = 0,
|
|
166
|
+
Climb = 1,
|
|
167
|
+
Dash = 2
|
|
168
|
+
};
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
2. Override `PhysCustom` in your CMC subclass:
|
|
172
|
+
```cpp
|
|
173
|
+
virtual void PhysCustom(float deltaTime, int32 Iterations) override;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
3. Enter the mode using `SetMovementMode`:
|
|
177
|
+
```cpp
|
|
178
|
+
SetMovementMode(MOVE_Custom, static_cast<uint8>(ECustomMovementMode::WallRun));
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
4. Handle transitions in `OnMovementModeChanged`:
|
|
182
|
+
```cpp
|
|
183
|
+
virtual void OnMovementModeChanged(EMovementMode PrevMode, uint8 PrevCustomMode) override;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Inside `PhysCustom`, dispatch on `CustomMovementMode` and implement your simulation. Call `CalcVelocity` for acceleration, `SafeMoveUpdatedComponent` for capsule movement, and `SetMovementMode` when transitioning out.
|
|
187
|
+
|
|
188
|
+
See `references/cmc-extension-patterns.md` for a complete wall-run implementation.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Network Prediction
|
|
193
|
+
|
|
194
|
+
CMC uses a client-side prediction and server reconciliation model. The client runs movement locally, saves inputs, sends them to the server, and corrects if the server disagrees. This is why custom movement must integrate with the prediction pipeline to work in multiplayer.
|
|
195
|
+
|
|
196
|
+
### FSavedMove_Character
|
|
197
|
+
|
|
198
|
+
Each client tick generates a saved move that records the input state:
|
|
199
|
+
|
|
200
|
+
Key fields: `bPressedJump`, `bWantsToCrouch`, `StartLocation`, `StartVelocity`, `SavedLocation`, `Acceleration`, `MaxSpeed`.
|
|
201
|
+
|
|
202
|
+
Key virtuals to override for custom data:
|
|
203
|
+
- `Clear()` — reset your custom fields
|
|
204
|
+
- `SetMoveFor(ACharacter*, float, FVector const&, FNetworkPredictionData_Client_Character&)` — capture your custom state from the CMC before the move executes
|
|
205
|
+
- `PrepMoveFor(ACharacter*)` — restore your custom state before replaying a move
|
|
206
|
+
- `GetCompressedFlags() const` — pack custom booleans into the `uint8` flags
|
|
207
|
+
- `CanCombineWith(const FSavedMovePtr&, ACharacter*, float)` — return `true` only if two moves are identical (enables bandwidth optimization)
|
|
208
|
+
- `PostUpdate(ACharacter*, EPostUpdateMode)` — called after the move executes
|
|
209
|
+
- `IsImportantMove(const FSavedMovePtr&)` — prevent combining if this move carries significant state
|
|
210
|
+
|
|
211
|
+
### CompressedFlags
|
|
212
|
+
|
|
213
|
+
The `uint8` returned by `GetCompressedFlags` has a fixed layout:
|
|
214
|
+
|
|
215
|
+
| Flag | Value | Purpose |
|
|
216
|
+
|------|-------|---------|
|
|
217
|
+
| `FLAG_JumpPressed` | `0x01` | Jump input |
|
|
218
|
+
| `FLAG_WantsToCrouch` | `0x02` | Crouch input |
|
|
219
|
+
| `FLAG_Reserved_1` | `0x04` | Engine reserved |
|
|
220
|
+
| `FLAG_Reserved_2` | `0x08` | Engine reserved |
|
|
221
|
+
| `FLAG_Custom_0` | `0x10` | Your custom flag |
|
|
222
|
+
| `FLAG_Custom_1` | `0x20` | Your custom flag |
|
|
223
|
+
| `FLAG_Custom_2` | `0x40` | Your custom flag |
|
|
224
|
+
| `FLAG_Custom_3` | `0x80` | Your custom flag |
|
|
225
|
+
|
|
226
|
+
You get four custom bits. For more complex state, use `FCharacterNetworkMoveData`.
|
|
227
|
+
|
|
228
|
+
### FNetworkPredictionData_Client_Character
|
|
229
|
+
|
|
230
|
+
Override `AllocateNewMove()` to return your custom `FSavedMove` subclass:
|
|
231
|
+
|
|
232
|
+
```cpp
|
|
233
|
+
class FMyNetworkPredictionData : public FNetworkPredictionData_Client_Character
|
|
234
|
+
{
|
|
235
|
+
public:
|
|
236
|
+
FMyNetworkPredictionData(const UCharacterMovementComponent& ClientMovement)
|
|
237
|
+
: FNetworkPredictionData_Client_Character(ClientMovement) {}
|
|
238
|
+
|
|
239
|
+
virtual FSavedMovePtr AllocateNewMove() override;
|
|
240
|
+
};
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The CMC exposes this via `GetPredictionData_Client()`, which you override to lazy-init your custom prediction data class.
|
|
244
|
+
|
|
245
|
+
### Modern Packed RPCs
|
|
246
|
+
|
|
247
|
+
UE5 uses packed move RPCs on `ACharacter`:
|
|
248
|
+
- `ServerMovePacked(FCharacterServerMovePackedBits)` — client to server
|
|
249
|
+
- `ClientMoveResponsePacked(FCharacterMoveResponsePackedBits)` — server to client
|
|
250
|
+
|
|
251
|
+
The old RPCs (`ServerMove`, `ServerMoveDual`, `ClientAdjustPosition`) are `DEPRECATED_CHARACTER_MOVEMENT_RPC`. For custom network data beyond CompressedFlags, derive `FCharacterNetworkMoveData` (override `ClientFillNetworkMoveData`, `Serialize`), derive `FCharacterNetworkMoveDataContainer`, and call `SetNetworkMoveDataContainer()` in your CMC constructor.
|
|
252
|
+
|
|
253
|
+
See `references/cmc-extension-patterns.md` for full FSavedMove and network data implementation templates.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Root Motion
|
|
258
|
+
|
|
259
|
+
Root motion allows animations or gameplay code to drive character movement directly. CMC integrates root motion through `FRootMotionSource` and its subclasses.
|
|
260
|
+
|
|
261
|
+
### FRootMotionSource
|
|
262
|
+
|
|
263
|
+
Base class fields:
|
|
264
|
+
- `Priority` — higher priority sources override lower
|
|
265
|
+
- `LocalID` — unique ID returned by `ApplyRootMotionSource`
|
|
266
|
+
- `InstanceName` — `FName` for retrieval and removal
|
|
267
|
+
- `Duration` — total time in seconds; **negative Duration means infinite** (runs until explicitly removed)
|
|
268
|
+
- `AccumulateMode` — `Override` (replaces other sources) or `Additive` (stacks)
|
|
269
|
+
|
|
270
|
+
### Subclasses
|
|
271
|
+
|
|
272
|
+
| Class | Key Parameters | Use Case |
|
|
273
|
+
|-------|---------------|----------|
|
|
274
|
+
| `FRootMotionSource_ConstantForce` | `Force`, `StrengthOverTime` | Knockback, wind |
|
|
275
|
+
| `FRootMotionSource_RadialForce` | `Location`, `Radius`, `Strength` | Explosions, vortex |
|
|
276
|
+
| `FRootMotionSource_MoveToForce` | `StartLocation`, `TargetLocation` | Dash to fixed point |
|
|
277
|
+
| `FRootMotionSource_MoveToDynamicForce` | `SetTargetLocation()` | Homing dash |
|
|
278
|
+
| `FRootMotionSource_JumpForce` | `Rotation`, `Distance`, `Height` | Targeted jump arc |
|
|
279
|
+
|
|
280
|
+
### CMC Methods
|
|
281
|
+
|
|
282
|
+
```cpp
|
|
283
|
+
// Returns uint16 LocalID for tracking
|
|
284
|
+
uint16 ApplyRootMotionSource(TSharedPtr<FRootMotionSource> Source);
|
|
285
|
+
|
|
286
|
+
// Retrieve by InstanceName
|
|
287
|
+
TSharedPtr<FRootMotionSource> GetRootMotionSource(FName InstanceName);
|
|
288
|
+
|
|
289
|
+
// Remove by InstanceName
|
|
290
|
+
void RemoveRootMotionSource(FName InstanceName);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Apply a constant knockback:
|
|
294
|
+
```cpp
|
|
295
|
+
auto Knockback = MakeShared<FRootMotionSource_ConstantForce>();
|
|
296
|
+
Knockback->InstanceName = TEXT("Knockback");
|
|
297
|
+
Knockback->Duration = 0.3f;
|
|
298
|
+
Knockback->Force = KnockbackDirection * KnockbackStrength;
|
|
299
|
+
Knockback->AccumulateMode = ERootMotionAccumulateMode::Override;
|
|
300
|
+
CMC->ApplyRootMotionSource(Knockback);
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Key Properties
|
|
306
|
+
|
|
307
|
+
| Property | Default | Description |
|
|
308
|
+
|----------|---------|-------------|
|
|
309
|
+
| `MaxWalkSpeed` | 600 | Maximum ground speed |
|
|
310
|
+
| `MaxAcceleration` | — | Rate of speed change |
|
|
311
|
+
| `GravityScale` | 1.0 | Multiplier on world gravity |
|
|
312
|
+
| `JumpZVelocity` | — | Initial vertical velocity on jump |
|
|
313
|
+
| `AirControl` | — | Lateral control while falling (0-1) |
|
|
314
|
+
| `GroundFriction` | — | Friction on ground surfaces |
|
|
315
|
+
| `BrakingDecelerationWalking` | — | Deceleration when no input on ground |
|
|
316
|
+
| `MaxStepHeight` | — | Maximum height of obstacles to step over |
|
|
317
|
+
| `WalkableFloorAngle` | 44.765 | Max walkable surface angle in degrees |
|
|
318
|
+
| `MaxWalkSpeedCrouched` | — | Speed while crouching |
|
|
319
|
+
| `MaxSwimSpeed` | — | Maximum speed in water |
|
|
320
|
+
| `MaxFlySpeed` | — | Maximum speed when flying |
|
|
321
|
+
| `MaxCustomMovementSpeed` | — | Speed cap for custom modes |
|
|
322
|
+
| `bOrientRotationToMovement` | — | Rotate character toward movement direction |
|
|
323
|
+
| `bUseControllerDesiredRotation` | — | Smoothly rotate toward controller rotation |
|
|
324
|
+
| `NetworkSmoothingMode` | — | Simulated proxy interpolation mode |
|
|
325
|
+
| `MaxSimulationTimeStep` | — | Cap on sub-step delta for stability |
|
|
326
|
+
| `MaxSimulationIterations` | — | Max physics iterations per frame |
|
|
327
|
+
| `bUseRVOAvoidance` | false | Enable RVO (reciprocal velocity obstacle) avoidance |
|
|
328
|
+
| `AvoidanceGroup` | — | `FNavAvoidanceMask` — group membership for avoidance filtering |
|
|
329
|
+
| `AvoidanceWeight` | — | float — higher weight yields right-of-way to other agents |
|
|
330
|
+
|
|
331
|
+
### Rotation
|
|
332
|
+
|
|
333
|
+
`bOrientRotationToMovement` and `bUseControllerDesiredRotation` are mutually exclusive in practice. The first rotates the character toward its velocity direction (third-person), the second smoothly rotates toward where the controller is facing (strafing shooter). Set one, not both.
|
|
334
|
+
|
|
335
|
+
### Gravity Direction (UE 5.4+)
|
|
336
|
+
|
|
337
|
+
```cpp
|
|
338
|
+
virtual void SetGravityDirection(const FVector& GravityDir);
|
|
339
|
+
FVector GetGravityDirection() const;
|
|
340
|
+
bool HasCustomGravity() const;
|
|
341
|
+
// Transform helpers (fields are protected — access via accessors)
|
|
342
|
+
FQuat GetWorldToGravityTransform() const;
|
|
343
|
+
FQuat GetGravityToWorldTransform() const;
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Custom gravity reorients the entire movement simulation. Walking, falling, and floor detection all respect the gravity direction when `HasCustomGravity()` returns `true`.
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## ACharacter API
|
|
351
|
+
|
|
352
|
+
`ACharacter` provides high-level movement actions that delegate to CMC:
|
|
353
|
+
|
|
354
|
+
### Jump
|
|
355
|
+
|
|
356
|
+
```cpp
|
|
357
|
+
void Jump(); // Sets bPressedJump, CMC handles velocity
|
|
358
|
+
void StopJumping(); // Clears jump input
|
|
359
|
+
bool CanJump() const; // Checks CanJumpInternal
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Properties: `bPressedJump`, `JumpMaxHoldTime`, `JumpMaxCount`, `JumpCurrentCount`.
|
|
363
|
+
|
|
364
|
+
`DoJump(bool bReplayingMoves, float DeltaTime)` is the internal method called by CMC to apply the jump velocity. In UE 5.5+ it takes two parameters; the old `DoJump(bool)` is deprecated.
|
|
365
|
+
|
|
366
|
+
### Crouch
|
|
367
|
+
|
|
368
|
+
```cpp
|
|
369
|
+
void Crouch(bool bClientSimulation = false);
|
|
370
|
+
void UnCrouch(bool bClientSimulation = false);
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
`bIsCrouched` is the replicated state. CMC handles capsule resizing and checks for clearance before uncrouching. Note: `CrouchedHalfHeight` on CMC is deprecated as of UE 5.0 — use `SetCrouchedHalfHeight()` / `GetCrouchedHalfHeight()` on the CMC instead.
|
|
374
|
+
|
|
375
|
+
### LaunchCharacter
|
|
376
|
+
|
|
377
|
+
```cpp
|
|
378
|
+
void LaunchCharacter(FVector LaunchVelocity, bool bXYOverride, bool bZOverride);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
When `bXYOverride` is `true`, replaces XY velocity entirely. When `false`, adds to existing velocity. Same logic for `bZOverride` on the Z axis. Automatically transitions to `MOVE_Falling`.
|
|
382
|
+
|
|
383
|
+
### Landed
|
|
384
|
+
|
|
385
|
+
```cpp
|
|
386
|
+
virtual void Landed(const FHitResult& Hit);
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Called when the character lands after falling. Override this for landing effects, damage, or animation triggers.
|
|
390
|
+
|
|
391
|
+
### Accessors
|
|
392
|
+
|
|
393
|
+
```cpp
|
|
394
|
+
UCharacterMovementComponent* GetCharacterMovement() const;
|
|
395
|
+
UCapsuleComponent* GetCapsuleComponent() const;
|
|
396
|
+
USkeletalMeshComponent* GetMesh() const;
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## Common Mistakes
|
|
402
|
+
|
|
403
|
+
**Modifying velocity directly instead of using CalcVelocity:**
|
|
404
|
+
```cpp
|
|
405
|
+
// WRONG: Bypasses friction, braking, and acceleration curves
|
|
406
|
+
Velocity = GetLastInputVector() * MaxWalkSpeed;
|
|
407
|
+
|
|
408
|
+
// RIGHT: Let CMC handle physics
|
|
409
|
+
CalcVelocity(DeltaTime, GroundFriction, false, BrakingDecelerationWalking);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
**Forgetting to call Super in PhysCustom:**
|
|
413
|
+
```cpp
|
|
414
|
+
// WRONG: Skips base class bookkeeping
|
|
415
|
+
void UMyCMC::PhysCustom(float DT, int32 Iter)
|
|
416
|
+
{
|
|
417
|
+
MyCustomLogic(DT, Iter);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// RIGHT: Call Super first (base PhysCustom is empty but future-proofs)
|
|
421
|
+
void UMyCMC::PhysCustom(float DT, int32 Iter)
|
|
422
|
+
{
|
|
423
|
+
Super::PhysCustom(DT, Iter);
|
|
424
|
+
MyCustomLogic(DT, Iter);
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
**Not saving custom state in FSavedMove:**
|
|
429
|
+
Custom movement flags that are not captured in `SetMoveFor` and restored in `PrepMoveFor` will be lost during server correction replays, causing desyncs.
|
|
430
|
+
|
|
431
|
+
**Using MoveUpdatedComponent instead of SafeMoveUpdatedComponent:**
|
|
432
|
+
`MoveUpdatedComponent` does not resolve penetration. In custom Phys* functions, always use `SafeMoveUpdatedComponent` to prevent the character from getting stuck inside geometry.
|
|
433
|
+
|
|
434
|
+
**Setting both rotation flags:**
|
|
435
|
+
`bOrientRotationToMovement` and `bUseControllerDesiredRotation` conflict. The character oscillates between two desired rotations each frame. Pick one based on your camera style.
|
|
436
|
+
|
|
437
|
+
**Using deprecated old-style RPCs:**
|
|
438
|
+
`ServerMove`, `ServerMoveDual`, `ClientAdjustPosition` are `DEPRECATED_CHARACTER_MOVEMENT_RPC`. Use the packed RPC pipeline and `FCharacterNetworkMoveData` for custom data.
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
## Reference Files
|
|
443
|
+
|
|
444
|
+
- `references/cmc-extension-patterns.md` — Complete CMC subclass templates: custom FSavedMove, prediction data, GetPredictionData_Client, wall-run PhysCustom, and custom network move data
|
|
445
|
+
- `references/movement-pipeline.md` — Phys* flow diagrams, floor detection chain, step-up logic, PhysWalking/PhysFalling breakdowns, and root motion replication flow
|
|
446
|
+
|
|
447
|
+
## Related Skills
|
|
448
|
+
|
|
449
|
+
- `/ue-networking-replication` — Replication fundamentals, RPCs, net roles; CMC prediction builds on this
|
|
450
|
+
- `/ue-animation-system` — Root motion from AnimMontage, animation-driven movement
|
|
451
|
+
- `/ue-physics-collision` — Sweep queries, collision channels used by CMC floor detection
|
|
452
|
+
- `/ue-gameplay-abilities` — GAS abilities that trigger movement modes or root motion
|
|
453
|
+
- `/ue-ai-navigation` — NavMesh integration, MOVE_NavWalking, RVO avoidance
|
|
454
|
+
- `/ue-input-system` — Enhanced Input feeding movement input to CMC
|
|
455
|
+
- `/ue-actor-component-architecture` — Component subobject patterns for CMC subclasses
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## Checklist
|
|
460
|
+
|
|
461
|
+
Validate before considering the work done:
|
|
462
|
+
|
|
463
|
+
- [ ] Custom movement is implemented through the CMC, not by setting locations directly
|
|
464
|
+
- [ ] Network prediction data was extended correctly for any new movement state
|
|
465
|
+
- [ ] Root motion sources are used for authored displacement
|
|
466
|
+
- [ ] Conventions in `docs/unreal/project-context.md` were read and followed
|
|
467
|
+
- [ ] The Common Mistakes section of this skill was reviewed against the change
|
|
468
|
+
|
|
469
|
+
**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.
|
|
470
|
+
|
|
471
|
+
## Next Steps
|
|
472
|
+
|
|
473
|
+
- `/ue-networking-replication` — validate prediction and correction
|
|
474
|
+
- `/code-review` — architectural and quality review of the change
|
|
475
|
+
- `/commit` — conventional commit once the change is verified
|