p.NetShowCorrections
p.NetShowCorrections
#Overview
name: p.NetShowCorrections
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether to draw client position corrections (red is incorrect, green is corrected).\n0: Disable, 1: Enable
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.NetShowCorrections is to enable or disable the visualization of client position corrections in the Unreal Engine’s character movement system. It is primarily used for debugging and development purposes, allowing developers to visually inspect discrepancies between client and server positions in networked gameplay.
This setting variable is primarily used in the character movement system, specifically within the CharacterMovementComponent. It is part of the Engine module and is closely related to network replication and client-server synchronization.
The value of this variable is set through a console command. It is defined as an FAutoConsoleVariableRef, which means it can be changed at runtime using the console command “p.NetShowCorrections”.
The associated variable NetShowCorrections interacts directly with p.NetShowCorrections. They share the same value and are used interchangeably in the code.
Developers should be aware that this variable is only available in non-shipping builds (#if !UE_BUILD_SHIPPING). It’s intended for development and debugging purposes and should not be relied upon in production code.
Best practices when using this variable include:
- Use it only for debugging and development purposes.
- Be aware that enabling it may have performance implications, especially in complex scenes or with many characters.
- Use it in conjunction with other debugging tools and logs to get a comprehensive view of character movement issues.
Regarding the associated variable NetShowCorrections:
The purpose of NetShowCorrections is the same as p.NetShowCorrections. It’s an internal representation of the console variable within the CharacterMovementCVars namespace.
This variable is used directly in the character movement and physics replication systems to control the visualization of client position corrections.
The value of NetShowCorrections is set by the console variable p.NetShowCorrections.
It interacts closely with other debugging variables like NetCorrectionLifetime, which controls how long the correction visualizations persist.
Developers should be aware that this variable is checked in multiple places throughout the character movement and physics replication code. Enabling it will trigger additional logging and potentially drawing debug information.
Best practices for NetShowCorrections are similar to those for p.NetShowCorrections. It should be used judiciously and only for debugging purposes, as it can impact performance and is not available in shipping builds.
#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:336
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
int32 NetShowCorrections = 0;
FAutoConsoleVariableRef CVarNetShowCorrections(
TEXT("p.NetShowCorrections"),
NetShowCorrections,
TEXT("Whether to draw client position corrections (red is incorrect, green is corrected).\n")
TEXT("0: Disable, 1: Enable"),
ECVF_Cheat);
float NetCorrectionLifetime = 4.f;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/CharacterMovementComponent.h:2574
Scope: file
Source code excerpt:
protected:
/** Event notification when client receives correction data from the server, before applying the data. Base implementation logs relevant data and draws debug info if "p.NetShowCorrections" is not equal to 0. */
ENGINE_API virtual void OnClientCorrectionReceived(class FNetworkPredictionData_Client_Character& ClientData, float TimeStamp, FVector NewLocation, FVector NewVelocity, UPrimitiveComponent* NewBase, FName NewBaseBoneName, bool bHasBase, bool bBaseRelativePosition, uint8 ServerMovementMode, FVector ServerGravityDirection);
/**
* Set custom struct used for client to server move RPC serialization.
* This is typically set in the constructor for this component and should persist for the lifetime of the component.
* @see GetNetworkMoveDataContainer(), ServerMovePacked_ServerReceive(), ServerMove_HandleMoveData()
#Associated Variable and Callsites
This variable is associated with another variable named NetShowCorrections
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:334
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
#if !UE_BUILD_SHIPPING
int32 NetShowCorrections = 0;
FAutoConsoleVariableRef CVarNetShowCorrections(
TEXT("p.NetShowCorrections"),
NetShowCorrections,
TEXT("Whether to draw client position corrections (red is incorrect, green is corrected).\n")
TEXT("0: Disable, 1: Enable"),
ECVF_Cheat);
float NetCorrectionLifetime = 4.f;
FAutoConsoleVariableRef CVarNetCorrectionLifetime(
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:10014
Scope (from outer to inner):
file
function void UCharacterMovementComponent::ServerMoveHandleClientError
Source code excerpt:
#if !UE_BUILD_SHIPPING
if (CharacterMovementCVars::NetShowCorrections != 0)
{
const FVector LocDiff = UpdatedComponent->GetComponentLocation() - ClientLoc;
const FString BaseString = MovementBase ? MovementBase->GetPathName(MovementBase->GetOutermost()) : TEXT("None");
UE_LOG(LogNetPlayerMovement, Warning, TEXT("*** Server: Error for %s at Time=%.3f is %3.3f LocDiff(%s) ClientLoc(%s) ServerLoc(%s) Base: %s Bone: %s Accel(%s) Velocity(%s)"),
*GetNameSafe(CharacterOwner), ClientTimeStamp, LocDiff.Size(), *LocDiff.ToString(), *ClientLoc.ToString(), *UpdatedComponent->GetComponentLocation().ToString(), *BaseString, *ServerData->PendingAdjustment.NewBaseBoneName.ToString(), *Accel.ToString(), *Velocity.ToString());
const float DebugLifetime = CharacterMovementCVars::NetCorrectionLifetime;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:10114
Scope (from outer to inner):
file
function bool UCharacterMovementComponent::ServerCheckClientError
Source code excerpt:
{
#if !UE_BUILD_SHIPPING
if (CharacterMovementCVars::NetShowCorrections != 0)
{
UE_LOG(LogNetPlayerMovement, Warning, TEXT("*** Server: %s is set to ignore error checks and corrections."), *GetNameSafe(CharacterOwner));
}
#endif // !UE_BUILD_SHIPPING
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/CharacterMovementComponent.cpp:10889
Scope (from outer to inner):
file
function void UCharacterMovementComponent::OnClientCorrectionReceived
Source code excerpt:
{
#if !UE_BUILD_SHIPPING
if (CharacterMovementCVars::NetShowCorrections != 0)
{
const FVector ClientLocAtCorrectedMove = ClientData.LastAckedMove.IsValid() ? ClientData.LastAckedMove->SavedLocation : UpdatedComponent->GetComponentLocation();
const FVector LocDiff = ClientLocAtCorrectedMove - NewLocation;
const FString NewBaseString = NewBase ? NewBase->GetPathName(NewBase->GetOutermost()) : TEXT("None");
UE_LOG(LogNetPlayerMovement, Warning, TEXT("*** Client: Error for %s at Time=%.3f is %3.3f LocDiff(%s) ClientLoc(%s) ServerLoc(%s) NewBase: %s NewBone: %s ClientVel(%s) ServerVel(%s) SavedMoves %d"),
*GetNameSafe(CharacterOwner), TimeStamp, LocDiff.Size(), *LocDiff.ToString(), *ClientLocAtCorrectedMove.ToString(), *NewLocation.ToString(), *NewBaseString, *NewBaseBoneName.ToString(), *Velocity.ToString(), *NewVelocity.ToString(), ClientData.SavedMoves.Num());
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsReplication.cpp:20
Scope (from outer to inner):
file
namespace CharacterMovementCVars
Source code excerpt:
namespace CharacterMovementCVars
{
extern int32 NetShowCorrections;
extern float NetCorrectionLifetime;
int32 SkipPhysicsReplication = 0;
static FAutoConsoleVariableRef CVarSkipPhysicsReplication(TEXT("p.SkipPhysicsReplication"), SkipPhysicsReplication, TEXT(""));
float NetPingExtrapolation = -1.0f;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsReplication.cpp:715
Scope (from outer to inner):
file
function bool FPhysicsReplication::ApplyRigidBodyState
Source code excerpt:
// Should we show the async part?
#if !UE_BUILD_SHIPPING
if (CharacterMovementCVars::NetShowCorrections != 0)
{
PhysicsTarget.ErrorHistory.bAutoAdjustMinMax = false;
PhysicsTarget.ErrorHistory.MinValue = 0.0f;
PhysicsTarget.ErrorHistory.MaxValue = 1.0f;
PhysicsTarget.ErrorHistory.AddSample(PhysicsTarget.AccumulatedErrorSeconds / ErrorAccumulationSeconds);
if (UWorld* OwningWorld = GetOwningWorld())