p.NetForceClientServerMoveLossPercent
p.NetForceClientServerMoveLossPercent
#Overview
name: p.NetForceClientServerMoveLossPercent
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Percent of ServerMove calls for client to not send.\nUseful for testing server force correction code.\n<=0: Disable, 0.05: 5% of checks will return failed, 1.0: never send server moves
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.NetForceClientServerMoveLossPercent is to simulate network packet loss for character movement in multiplayer games. It allows developers to test and debug server-side correction mechanisms by intentionally dropping a percentage of client-to-server movement updates.
This setting variable is primarily used by the Character Movement Component, which is part of Unreal Engine’s gameplay framework. It’s specifically utilized in the networking and replication system for character movement.
The value of this variable is set through the Unreal Engine console variable system. It’s defined as a static float variable within the CharacterMovementCVars namespace and exposed as a console variable using FAutoConsoleVariableRef.
The associated variable NetForceClientServerMoveLossPercent directly interacts with p.NetForceClientServerMoveLossPercent. They share the same value and are used interchangeably in the code.
Developers must be aware that this variable is intended for testing and debugging purposes only. It’s marked with ECVF_Cheat flag, indicating it should not be used in production builds. The variable affects the frequency of ServerMove calls that the client sends to the server, which can significantly impact gameplay and network performance.
Best practices when using this variable include:
- Only use it in development and testing environments.
- Use it in conjunction with other networking debugging tools to get a comprehensive view of movement replication issues.
- Test with various percentages to simulate different network conditions.
- Be aware that setting this value too high can make the game unplayable, as it will prevent character movement updates from reaching the server.
Regarding the associated variable NetForceClientServerMoveLossPercent: Its purpose is identical to p.NetForceClientServerMoveLossPercent, serving as the actual storage for the console variable’s value. It’s used directly in the UCharacterMovementComponent::ReplicateMoveToServer function to determine whether a ServerMove should be sent or dropped. The variable is checked against a random value to decide if a move should be dropped, based on the specified percentage.
#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:366
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
static float NetForceClientServerMoveLossPercent = 0.f;
FAutoConsoleVariableRef CVarNetForceClientServerMoveLossPercent(
TEXT("p.NetForceClientServerMoveLossPercent"),
NetForceClientServerMoveLossPercent,
TEXT("Percent of ServerMove calls for client to not send.\n")
TEXT("Useful for testing server force correction code.\n")
TEXT("<=0: Disable, 0.05: 5% of checks will return failed, 1.0: never send server moves"),
ECVF_Cheat);
#Associated Variable and Callsites
This variable is associated with another variable named NetForceClientServerMoveLossPercent
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:364
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
ECVF_Cheat);
static float NetForceClientServerMoveLossPercent = 0.f;
FAutoConsoleVariableRef CVarNetForceClientServerMoveLossPercent(
TEXT("p.NetForceClientServerMoveLossPercent"),
NetForceClientServerMoveLossPercent,
TEXT("Percent of ServerMove calls for client to not send.\n")
TEXT("Useful for testing server force correction code.\n")
TEXT("<=0: Disable, 0.05: 5% of checks will return failed, 1.0: never send server moves"),
ECVF_Cheat);
static float NetForceClientServerMoveLossDuration = 0.f;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:8684
Scope (from outer to inner):
file
function void UCharacterMovementComponent::ReplicateMoveToServer
Source code excerpt:
UE_LOG(LogNetPlayerMovement, Log, TEXT("Drop ServerMove, %.2f time remains"), CharacterMovementCVars::NetForceClientServerMoveLossDuration - TimeSinceLossStart);
}
else if (CharacterMovementCVars::NetForceClientServerMoveLossPercent != 0.f && (RandomStream.FRand() < CharacterMovementCVars::NetForceClientServerMoveLossPercent))
{
bSendServerMove = false;
ClientData->DebugForcedPacketLossTimerStart = (CharacterMovementCVars::NetForceClientServerMoveLossDuration > 0) ? MyWorld->RealTimeSeconds : 0.0f;
UE_LOG(LogNetPlayerMovement, Log, TEXT("Drop ServerMove, %.2f time remains"), CharacterMovementCVars::NetForceClientServerMoveLossDuration);
}
else