p.NetUseBaseRelativeVelocity
p.NetUseBaseRelativeVelocity
#Overview
name: p.NetUseBaseRelativeVelocity
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If enabled, character velocity corrections will be treated as relative to dynamic movement bases.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.NetUseBaseRelativeVelocity is to control how character velocity corrections are treated in relation to dynamic movement bases in networked gameplay. It is primarily used for the character movement system in Unreal Engine 5.
This setting variable is utilized by the Character Movement Component, which is part of the Engine module in Unreal Engine. It specifically affects the networking and replication aspects of character movement.
The value of this variable is set through a console variable (CVar) system. It is initialized to 1 (enabled) by default, but can be changed at runtime through console commands or configuration files.
The associated variable NetUseBaseRelativeVelocity directly interacts with p.NetUseBaseRelativeVelocity. They share the same value and purpose.
Developers must be aware that this variable affects how velocity corrections are calculated and applied in networked games, particularly when characters are moving on dynamic bases (like moving platforms). When enabled, it treats velocity corrections as relative to the movement base, which can lead to more accurate movement replication in certain scenarios.
Best practices when using this variable include:
- Testing thoroughly with both enabled and disabled states to ensure desired movement behavior across different network conditions.
- Considering the impact on gameplay, especially in games with complex moving platforms or other dynamic movement bases.
- Potentially exposing this as a configurable option for different game modes or server configurations.
Regarding the associated variable NetUseBaseRelativeVelocity:
This is an internal variable used within the CharacterMovementComponent to actually implement the behavior controlled by p.NetUseBaseRelativeVelocity. It’s used in the ServerMoveHandleClientError function to determine how to store and apply velocity corrections.
When enabled, it causes the server to store the character’s velocity relative to its movement base when preparing network corrections. This can lead to more accurate movement replication when characters are on moving platforms or other dynamic bases.
Developers should be aware that changing p.NetUseBaseRelativeVelocity will directly affect the behavior of this internal variable, and thus the network movement correction system for characters.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:260
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
static int32 NetUseBaseRelativeVelocity = 1;
FAutoConsoleVariableRef CVarNetUseBaseRelativeVelocity(
TEXT("p.NetUseBaseRelativeVelocity"),
NetUseBaseRelativeVelocity,
TEXT("If enabled, character velocity corrections will be treated as relative to dynamic movement bases."));
static int32 UseTargetVelocityOnImpact = 1;
FAutoConsoleVariableRef CVarUseTargetVelocityOnImpact(
TEXT("p.UseTargetVelocityOnImpact"),
#Associated Variable and Callsites
This variable is associated with another variable named NetUseBaseRelativeVelocity
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:258
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
TEXT("If enabled, character acceleration will be treated as relative to dynamic movement bases."));
static int32 NetUseBaseRelativeVelocity = 1;
FAutoConsoleVariableRef CVarNetUseBaseRelativeVelocity(
TEXT("p.NetUseBaseRelativeVelocity"),
NetUseBaseRelativeVelocity,
TEXT("If enabled, character velocity corrections will be treated as relative to dynamic movement bases."));
static int32 UseTargetVelocityOnImpact = 1;
FAutoConsoleVariableRef CVarUseTargetVelocityOnImpact(
TEXT("p.UseTargetVelocityOnImpact"),
UseTargetVelocityOnImpact, TEXT("When disabled, we recalculate velocity after impact by comparing our position before we moved to our position after we moved. This doesn't work correctly when colliding with physics objects, so setting this to 1 fixes this one the hit object is moving."));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:9999
Scope (from outer to inner):
file
function void UCharacterMovementComponent::ServerMoveHandleClientError
Source code excerpt:
{
ServerData->PendingAdjustment.NewLoc = CharacterOwner->GetBasedMovement().Location;
if (CharacterMovementCVars::NetUseBaseRelativeVelocity)
{
// Store world velocity converted to local space of movement base
ServerData->PendingAdjustment.bBaseRelativeVelocity = true;
const FVector CurrentVelocity = ServerData->PendingAdjustment.NewVel;
MovementBaseUtility::TransformDirectionToLocal(MovementBase, MovementBaseBoneName, CurrentVelocity, ServerData->PendingAdjustment.NewVel);
}