net.DoPacketOrderCorrection

net.DoPacketOrderCorrection

#Overview

name: net.DoPacketOrderCorrection

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of net.DoPacketOrderCorrection is to control whether the Unreal Engine networking system attempts to fix ‘out of order’ packet sequences by caching packets and waiting for the missing sequence.

This setting variable is primarily used by the Unreal Engine’s networking subsystem, specifically within the network connection management module. It’s referenced in the NetConnection.cpp file, which is part of the Engine’s runtime.

The value of this variable is set as a console variable (CVar) with a default value of 1 (enabled). It can be changed at runtime through console commands or configuration files.

The variable interacts with several other networking-related variables, including:

  1. net.PacketOrderCorrectionEnableThreshold
  2. net.PacketOrderMaxMissingPackets

Developers must be aware that enabling this feature (which is the default) may introduce additional latency in packet processing, as the system will wait for out-of-order packets to arrive before processing. However, it can improve the reliability of network communication by ensuring packets are processed in the correct order.

Best practices when using this variable include:

  1. Monitor network performance to determine if packet order correction is necessary for your specific use case.
  2. Consider disabling it in scenarios where minimizing latency is more critical than ensuring perfect packet order.
  3. Adjust the related threshold variables to fine-tune the behavior based on your network conditions.

Regarding the associated variable CVarNetDoPacketOrderCorrection:

The purpose of CVarNetDoPacketOrderCorrection is to provide programmatic access to the net.DoPacketOrderCorrection setting within the C++ code.

This variable is used directly in the networking subsystem, specifically in the UNetConnection class when processing received packets.

The value of CVarNetDoPacketOrderCorrection is set automatically based on the net.DoPacketOrderCorrection console variable.

It interacts closely with CVarNetPacketOrderCorrectionEnableThreshold, which determines how many out-of-order packets must be detected before the correction mechanism is enabled.

Developers should be aware that this variable is checked on the game thread (GetValueOnAnyThread()), which means changes to the console variable will be reflected in the game’s behavior immediately.

Best practices for using CVarNetDoPacketOrderCorrection include:

  1. Use it in conjunction with logging or telemetry to monitor when packet order correction is being applied.
  2. Consider exposing this setting in your game’s network options if you want to give players control over this behavior.
  3. Be cautious about frequently toggling this value, as it could lead to inconsistent network behavior.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:81

Scope: file

Source code excerpt:

#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."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderCorrectionEnableThreshold(TEXT("net.PacketOrderCorrectionEnableThreshold"), 1,
	TEXT("The number of 'out of order' packet sequences that need to occur, before correction is enabled."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderMaxMissingPackets(TEXT("net.PacketOrderMaxMissingPackets"), 3,

#Associated Variable and Callsites

This variable is associated with another variable named CVarNetDoPacketOrderCorrection. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:81

Scope: file

Source code excerpt:

#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."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderCorrectionEnableThreshold(TEXT("net.PacketOrderCorrectionEnableThreshold"), 1,
	TEXT("The number of 'out of order' packet sequences that need to occur, before correction is enabled."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderMaxMissingPackets(TEXT("net.PacketOrderMaxMissingPackets"), 3,

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:3024

Scope (from outer to inner):

file
function     void UNetConnection::ReceivedPacket

Source code excerpt:

			Driver->IncreaseTotalOutOfOrderPacketsLost();

			if (!PacketOrderCache.IsSet() && CVarNetDoPacketOrderCorrection.GetValueOnAnyThread() != 0)
			{
				int32 EnableThreshold = CVarNetPacketOrderCorrectionEnableThreshold.GetValueOnAnyThread();

				if (TotalOutOfOrderPacketsLost >= EnableThreshold)
				{
					UE_LOG(LogNet, Verbose, TEXT("Hit threshold of %i 'out of order' packet sequences. Enabling out of order packet correction."), EnableThreshold);