<aside> 💡 Prerequisite Topics In order to understand and use the content on this page, make sure you are familiar with the following topics:
The character movement component is an Actor Component that provides an encapsulated movement system with common modes of movement for humanoid characters, including walking, falling, swimming, and flying. The character movement component also features robust network gameplay integration. Its default movement modes are all built to replicate by default, and it provides a framework to help developers create custom networked movement.
UCharacterMovementComponent
comes preattached to the ACharacter
Actor class and any Blueprints derived from it.
During its TickComponent
function, UCharacterMovementComponent
will call PerformMovement
to calculate desired acceleration within the world based on what movement mode it is currently using as well as the player's input variables, commonly represented with the control input variables in APlayerController
. Once movement calculations are finalized, UCharacterMovementComponent
applies the final movement to the owning character.
<aside>
💡 While ACharacter
is derived from APawn
, Characters are not simply Pawns that have a character movement component added to them. UCharacterMovementComponent
and ACharacter
are designed to be used together, as ACharacter
overrides several replicated variables and functions specifically to facilitate replication in UCharacterMovementComponent
.
</aside>
The PerformMovement
function is responsible for physically moving the character in the game's world. In a non-networked game, UCharacterMovementComponent
calls PerformMovement
directly each tick. In a network game, PerformMovement
is called by specialized functions for servers and clients to either perform the initial movement on a player's local machine or reproduce that movement on remote machines.
PerformMovement
handles the following:
StartNewPhysics
, which selects a Phys*
function based on what movement mode the character is using.Each movement mode has its own Phys*
function that is responsible for calculating velocity and acceleration. For example, PhysWalking
determines the character's movement physics when moving on the ground, while PhysFalling
determines how it behaves in the air. If you wanted to debug the specifics of these behaviors, you would look inside each of these functions.
If a movement mode changes during a tick, such as when a character starts falling or collides with an object, the Phys*
functions call StartNewPhysics
again to continue the character's motion in the new movement mode. StartNewPhysics
and the Phys*
functions each pass through the number of iterations of StartNewPhysics
that have occurred. The parameter MaxSimulationIterations
is the maximum number of times this recursion is allowed.
UCharacterMovementComponent
uses its owner's network role to determine how to replicate movement. The three network roles are as follows:
Network Role | Description |
---|---|
Autonomous Proxy | The character is on its owning client's machine, being controlled locally by a player. |
Authority | The character exists on the server hosting the game. |
Simulated Proxy | The character exists on any other client that can see the remotely-controlled character, whether it's being controlled by an AI on the server or by an autonomous proxy on a different client. |
The replication process follows a cycle within the TickComponent
function, which repeats itself on every tick. As the character performs movement, copies of it on all the different machines in the network game make Remote Procedure Calls (RPCs) to each other to synchronize movement information, with different network roles using different execution paths as appropriate.
The table below provides a step-by-step overview of what UCharacterMovementComponent
does on each machine during this process: