np2.TimeDilationAmount
np2.TimeDilationAmount
#Overview
name: np2.TimeDilationAmount
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
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.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of np2.TimeDilationAmount is to control the time dilation in the network physics system of Unreal Engine 5. It is used to adjust the physics simulation speed on the server-side to maintain synchronization between the client and server.
This setting variable is primarily used in the Engine module, specifically within the PlayerController component. It’s part of the network physics system, which is responsible for maintaining consistent physics simulations across networked game sessions.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0.01, which represents a 1% time dilation. Developers can modify this value at runtime using console commands.
np2.TimeDilationAmount interacts with several other variables:
- TimeDilationEscalation: Determines whether the time dilation should be escalated based on the number of ticks that need adjustment.
- TimeDilationEscalationDecay: Controls the decay rate of escalated time dilation.
- TickOffsetCorrectionLimit: Sets a limit for tick offset correction.
Developers must be aware that this variable directly affects the physics simulation speed. A value of 0 disables time dilation entirely. The value is in percent, where 0.01 equals 1% dilation. For example, a value of 1.0/0.01 = 100 means that over the time it usually takes to tick 100 physics steps, the system will tick 99 or 101 steps, depending on whether it dilates up or down.
Best practices when using this variable include:
- Carefully tuning the value to balance network synchronization and gameplay feel.
- Monitoring its effects on gameplay, especially in multiplayer scenarios.
- Using it in conjunction with other network physics settings for optimal results.
- Testing thoroughly with various network conditions to ensure robust behavior.
The associated variable TimeDilationAmount is essentially the same as np2.TimeDilationAmount. It’s the C++ variable that holds the value set by the console variable. It’s used in the actual code logic to calculate the time dilation factor applied to the physics simulation. The same considerations and best practices apply to this variable as well.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:135
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
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."));
float TimeDilationEscalationDecay = 0.05f;
FAutoConsoleVariableRef CVarTimeDilationEscalationDecay(TEXT("np2.TimeDilationEscalationDecay"), TimeDilationEscalationDecay, TEXT("Value is a multiplier, Default: 0.05. For each escalated TimeDilation amount, also decay by this much. Disable by setting to 0."));
#Associated Variable and Callsites
This variable is associated with another variable named TimeDilationAmount
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:134
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
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."));
float TimeDilationEscalationDecay = 0.05f;
FAutoConsoleVariableRef CVarTimeDilationEscalationDecay(TEXT("np2.TimeDilationEscalationDecay"), TimeDilationEscalationDecay, TEXT("Value is a multiplier, Default: 0.05. For each escalated TimeDilation amount, also decay by this much. Disable by setting to 0."));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:6266
Scope (from outer to inner):
file
function void APlayerController::ServerSendLatestAsyncPhysicsTimestamp_Implementation
Source code excerpt:
// Calculate desired dilation and send to client
const float TimeDilationDecay = FMath::Clamp(1.0f - (NetworkPhysicsCvars::TimeDilationEscalationDecay * FMath::Abs(CurrentFrameBufferOffset)), NetworkPhysicsCvars::TimeDilationEscalationDecayMax, 1.0f);
float CalculatedTimeDilation = 1.0f + ((NetworkPhysicsCvars::TimeDilationAmount * -CurrentFrameBufferOffset) * TimeDilationDecay);
CalculatedTimeDilation = FMath::Clamp(CalculatedTimeDilation, NetworkPhysicsCvars::TimeDilationMin, NetworkPhysicsCvars::TimeDilationMax);
ClientAckTimeDilation(CalculatedTimeDilation, ActualTimestamp.LocalFrame);
}
}