np2.PredictionAsyncFrameBuffer
np2.PredictionAsyncFrameBuffer
#Overview
name: np2.PredictionAsyncFrameBuffer
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Additional frame offset to be added to the local to server offset used by network prediction
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of np2.PredictionAsyncFrameBuffer is to provide an additional frame offset for network prediction in the physics system. This setting variable is used to improve the accuracy of client-side prediction in networked multiplayer games by adding a buffer to compensate for network latency.
This setting variable is primarily used in the Engine module, specifically within the PlayerController system. It’s part of the network physics prediction mechanism, which is crucial for smooth gameplay in multiplayer environments.
The value of this variable is set through the Unreal Engine’s console variable system. It’s initialized with a default value of 3, but can be changed at runtime using console commands or through configuration files.
The np2.PredictionAsyncFrameBuffer interacts closely with other network physics-related variables, such as TickOffsetUpdateInterval and TickOffsetCorrectionLimit. It’s also associated with a deprecated variable named NetworkPhysicsPredictionFrameOffset, which serves the same purpose but is marked for removal in version 5.4 of Unreal Engine.
Developers must be aware that this variable directly affects the behavior of network prediction. Increasing the value can improve prediction accuracy but may introduce more latency, while decreasing it can reduce latency but potentially lead to more prediction errors.
Best practices when using this variable include:
- Carefully tuning the value based on your game’s specific networking requirements and player experience.
- Testing thoroughly with various network conditions to ensure optimal performance.
- Considering the trade-off between prediction accuracy and perceived responsiveness.
- Monitoring and adjusting this value in conjunction with other network-related settings for best results.
Regarding the associated variable PredictionAsyncFrameBuffer:
This is the actual integer variable that stores the value set by np2.PredictionAsyncFrameBuffer. It’s used directly in the code to modify the ServerFrame of the FAsyncPhysicsTimestamp structure.
The purpose of PredictionAsyncFrameBuffer is the same as np2.PredictionAsyncFrameBuffer - to provide an additional frame offset for network prediction.
This variable is used in the Engine module, specifically within the PlayerController class in the ServerSendLatestAsyncPhysicsTimestamp_Implementation function.
The value of PredictionAsyncFrameBuffer is set through the console variable system, initialized with a default value of 3.
It interacts directly with the FAsyncPhysicsTimestamp structure, modifying the ServerFrame member.
Developers should be aware that changes to np2.PredictionAsyncFrameBuffer will directly affect this variable, and thus the behavior of the network prediction system.
Best practices include ensuring that any code that needs to access this value does so through the console variable system rather than directly modifying the PredictionAsyncFrameBuffer variable, to maintain consistency and allow for runtime configuration.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:126
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
int32 PredictionAsyncFrameBuffer = 3;
FAutoConsoleVariableRef CVarPredictionAsyncFrameBuffer(TEXT("np2.PredictionAsyncFrameBuffer"), PredictionAsyncFrameBuffer, TEXT("Additional frame offset to be added to the local to server offset used by network prediction"));
int32 TickOffsetUpdateInterval = 10;
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."));
#Associated Variable and Callsites
This variable is associated with another variable named PredictionAsyncFrameBuffer
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:125
Scope (from outer to inner):
file
namespace NetworkPhysicsCvars
Source code excerpt:
FAutoConsoleVariableRef CVarNetworkPhysicsPredictionFrameOffset(TEXT("np2.NetworkPhysicsPredictionFrameOffset"), NetworkPhysicsPredictionFrameOffset, TEXT("(DEPRECATED 5.4, use np2.PredictionAsyncFrameBuffer instead) Additional frame offset to be added to the local to server offset used by network prediction"));
int32 PredictionAsyncFrameBuffer = 3;
FAutoConsoleVariableRef CVarPredictionAsyncFrameBuffer(TEXT("np2.PredictionAsyncFrameBuffer"), PredictionAsyncFrameBuffer, TEXT("Additional frame offset to be added to the local to server offset used by network prediction"));
int32 TickOffsetUpdateInterval = 10;
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."));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PlayerController.cpp:6233
Scope (from outer to inner):
file
function void APlayerController::ServerSendLatestAsyncPhysicsTimestamp_Implementation
Source code excerpt:
// Get current server timestamp and add the frame buffer to the ServerFrame
FAsyncPhysicsTimestamp ActualTimestamp = GetPhysicsTimestamp();
ActualTimestamp.ServerFrame += NetworkPhysicsCvars::PredictionAsyncFrameBuffer;
// Mark offset as assigned when we get a valid predicted server frame.
const int32 PredictedServerFrame = Timestamp.ServerFrame;
bNetworkPhysicsTickOffsetAssigned |= PredictedServerFrame != INDEX_NONE;
// Send update to client if offset is not assigned or over correction limit