net.ForceNetFlush
net.ForceNetFlush
#Overview
name: net.ForceNetFlush
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Immediately flush send buffer when written to (helps trace packet writes - WARNING: May be unstable).
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.ForceNetFlush is to immediately flush the send buffer when it is written to. This setting is primarily used for debugging and tracing packet writes in networked gameplay scenarios.
This setting variable is primarily used in the networking subsystem of Unreal Engine, specifically within the NetConnection module. It’s referenced in the Engine’s runtime, as seen in the file path “Engine/Source/Runtime/Engine/Private/NetConnection.cpp”.
The value of this variable is set as a console variable (CVar) with an initial value of 0. It can be changed at runtime through the console or programmatically.
The associated variable CVarForceNetFlush directly interacts with net.ForceNetFlush. They share the same value and purpose.
Developers must be aware of several important points when using this variable:
- It’s only available in non-shipping builds (#if !UE_BUILD_SHIPPING).
- Enabling this option may lead to instability, as warned in the comment.
- It’s primarily intended for debugging purposes, not for regular gameplay.
- When enabled, it forces the net connection to flush its send buffer immediately after writing, which can significantly impact performance.
Best practices for using this variable include:
- Only use it when necessary for debugging network issues.
- Be prepared for potential instability when enabled.
- Disable it in production or shipping builds.
- Use it in conjunction with other network debugging tools for comprehensive analysis.
Regarding the associated variable CVarForceNetFlush:
The purpose of CVarForceNetFlush is identical to net.ForceNetFlush. It’s an auto console variable that controls the immediate flushing of the send buffer in network operations.
This variable is used in the same networking subsystem and NetConnection module as net.ForceNetFlush.
The value is set initially to 0 and can be changed at runtime.
CVarForceNetFlush directly interacts with the net.ForceNetFlush console command. They are essentially two interfaces to the same functionality.
Developers should be aware that:
- This variable is checked in the WriteBitsToSendBufferInternal function of UNetConnection.
- When its value is non-zero, it triggers a FlushNet() call, which immediately sends out all queued network data.
Best practices for CVarForceNetFlush are the same as for net.ForceNetFlush, given they are essentially the same setting accessed in different ways.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:77
Scope: file
Source code excerpt:
#if !UE_BUILD_SHIPPING
static TAutoConsoleVariable<int32> CVarForceNetFlush(TEXT("net.ForceNetFlush"), 0,
TEXT("Immediately flush send buffer when written to (helps trace packet writes - WARNING: May be unstable)."));
#endif
static TAutoConsoleVariable<int32> CVarNetDoPacketOrderCorrection(TEXT("net.DoPacketOrderCorrection"), 1,
TEXT("Whether or not to try to fix 'out of order' packet sequences, by caching packets and waiting for the missing sequence."));
#Associated Variable and Callsites
This variable is associated with another variable named CVarForceNetFlush
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:77
Scope: file
Source code excerpt:
#if !UE_BUILD_SHIPPING
static TAutoConsoleVariable<int32> CVarForceNetFlush(TEXT("net.ForceNetFlush"), 0,
TEXT("Immediately flush send buffer when written to (helps trace packet writes - WARNING: May be unstable)."));
#endif
static TAutoConsoleVariable<int32> CVarNetDoPacketOrderCorrection(TEXT("net.DoPacketOrderCorrection"), 1,
TEXT("Whether or not to try to fix 'out of order' packet sequences, by caching packets and waiting for the missing sequence."));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:3991
Scope (from outer to inner):
file
function int32 UNetConnection::WriteBitsToSendBufferInternal
Source code excerpt:
if (GetFreeSendBufferBits() == 0
#if !UE_BUILD_SHIPPING
|| CVarForceNetFlush.GetValueOnAnyThread() != 0
#endif
)
{
FlushNet();
}