np2.TickOffsetCorrectionLimit
np2.TickOffsetCorrectionLimit
#Overview
name: np2.TickOffsetCorrectionLimit
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If the client gets out of sync with physics ticks more than this limit, cut the losses and reset the offset.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of np2.TickOffsetCorrectionLimit is to control the synchronization between client and server physics ticks in networked gameplay. It sets a threshold for when the client’s physics simulation should be reset to match the server’s state.
This setting variable is primarily used in the networking and physics subsystems of Unreal Engine 5. Specifically, it’s utilized in the PlayerController module, which is responsible for managing player input and synchronization in networked games.
The value of this variable is set within the NetworkPhysicsCvars namespace in the PlayerController.cpp file. It’s initialized with a default value of 10 and can be modified at runtime through the console variable system.
The np2.TickOffsetCorrectionLimit interacts closely with other networking and physics-related variables, such as TickOffsetUpdateInterval, TimeDilationAmount, and TimeDilationEscalation. These variables work together to manage the synchronization of physics simulations between client and server.
Developers must be aware that this variable directly impacts the tolerance for discrepancies between client and server physics states. Setting it too low might result in frequent resets of client physics, while setting it too high could lead to noticeable desynchronization.
Best practices when using this variable include:
- Carefully tuning it based on the specific needs of your game, considering factors like network latency and physics complexity.
- Monitoring its effects in conjunction with other related variables to achieve optimal synchronization.
- Testing thoroughly with various network conditions to ensure a smooth player experience.
Regarding the associated variable TickOffsetCorrectionLimit, it’s important to note that this is the actual integer variable that stores the value, while np2.TickOffsetCorrectionLimit is the console variable that exposes it for runtime modification. They are essentially two representations of the same setting, one for internal use in the code and one for external access via the console.
The TickOffsetCorrectionLimit is used in the ServerSendLatestAsyncPhysicsTimestamp_Implementation function to determine when to reset the client’s physics state. If the absolute difference between the predicted and actual server frame exceeds this limit, the client’s network physics timestamp is reset.
Developers should be mindful of how changes to this variable can affect gameplay, especially in fast-paced or physics-heavy games where precise synchronization is crucial.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:132
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
int32 TickOffsetCorrectionLimit = 10;
FAutoConsoleVariableRef CVarTickOffsetCorrectionLimit(TEXT("np2.TickOffsetCorrectionLimit"), TickOffsetCorrectionLimit, TEXT("If the client gets out of sync with physics ticks more than this limit, cut the losses and reset the offset."));
float TimeDilationAmount = 0.01f;
FAutoConsoleVariableRef CVarTimeDilationAmount(TEXT("np2.TimeDilationAmount"), TimeDilationAmount, TEXT("Server-side CVar, Disable TimeDilation by setting to 0 | Default: 0.01 | Value is in percent where 0.01 = 1% dilation. Example: 1.0/0.01 = 100, meaning that over the time it usually takes to tick 100 physics steps we will tick 99 or 101 depending on if we dilate up or down."));
bool TimeDilationEscalation = true;
FAutoConsoleVariableRef CVarTimeDilationEscalation(TEXT("np2.TimeDilationEscalation"), TimeDilationEscalation, TEXT("Server-side CVar, Dilate the time more depending on how many ticks we need to adjust. When set to false we use the set TimeDilationAmount and wait the amount of time it takes to perform correct the offset. When set to true we multiply the TimeDilationAmount with the buffer offset count which will correct the offset in one TimeDilationAmount cycle."));
#Associated Variable and Callsites
This variable is associated with another variable named TickOffsetCorrectionLimit
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:131
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
FAutoConsoleVariableRef CVarTickOffsetUpdateInterval(TEXT("np2.TickOffsetUpdateInterval"), TickOffsetUpdateInterval, TEXT("How many physics ticks to wait between each tick offset update. Lowest viable value = 1, which means update each tick. Deactivate physics offset updates by setting to 0 or negative value."));
int32 TickOffsetCorrectionLimit = 10;
FAutoConsoleVariableRef CVarTickOffsetCorrectionLimit(TEXT("np2.TickOffsetCorrectionLimit"), TickOffsetCorrectionLimit, TEXT("If the client gets out of sync with physics ticks more than this limit, cut the losses and reset the offset."));
float TimeDilationAmount = 0.01f;
FAutoConsoleVariableRef CVarTimeDilationAmount(TEXT("np2.TimeDilationAmount"), TimeDilationAmount, TEXT("Server-side CVar, Disable TimeDilation by setting to 0 | Default: 0.01 | Value is in percent where 0.01 = 1% dilation. Example: 1.0/0.01 = 100, meaning that over the time it usually takes to tick 100 physics steps we will tick 99 or 101 depending on if we dilate up or down."));
bool TimeDilationEscalation = true;
FAutoConsoleVariableRef CVarTimeDilationEscalation(TEXT("np2.TimeDilationEscalation"), TimeDilationEscalation, TEXT("Server-side CVar, Dilate the time more depending on how many ticks we need to adjust. When set to false we use the set TimeDilationAmount and wait the amount of time it takes to perform correct the offset. When set to true we multiply the TimeDilationAmount with the buffer offset count which will correct the offset in one TimeDilationAmount cycle."));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:6241
Scope (from outer to inner):
file
function void APlayerController::ServerSendLatestAsyncPhysicsTimestamp_Implementation
Source code excerpt:
// Send update to client if offset is not assigned or over correction limit
// Note that we are sending the current ServerFrame along with the frame buffer added, to the client.
if (!bNetworkPhysicsTickOffsetAssigned || FMath::Abs(PredictedServerFrame - ActualTimestamp.ServerFrame) > NetworkPhysicsCvars::TickOffsetCorrectionLimit)
{
Timestamp.ServerFrame = ActualTimestamp.ServerFrame;
NetworkPhysicsTickOffset = Timestamp.ServerFrame - Timestamp.LocalFrame;
ClientSetupNetworkPhysicsTimestamp(Timestamp); /* Reliable RPC */
}