net.PacketOrderCorrectionEnableThreshold

net.PacketOrderCorrectionEnableThreshold

#Overview

name: net.PacketOrderCorrectionEnableThreshold

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.PacketOrderCorrectionEnableThreshold is to control the network packet order correction system in Unreal Engine. Specifically, it determines the number of out-of-order packet sequences that need to occur before the packet order correction mechanism is enabled.

This setting variable is primarily used by the networking subsystem of Unreal Engine, particularly within the UNetConnection class, which handles network connections for multiplayer gameplay.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 in the source code, but can be modified at runtime through console commands or configuration files.

The associated variable CVarNetPacketOrderCorrectionEnableThreshold directly interacts with net.PacketOrderCorrectionEnableThreshold. They share the same value and purpose.

Developers must be aware that this variable affects the engine’s tolerance for out-of-order packets before it starts attempting to correct the order. A lower value will make the system more aggressive in correcting packet order, while a higher value will allow more out-of-order packets before correction begins.

Best practices when using this variable include:

  1. Carefully consider the network conditions of your game when adjusting this value.
  2. Monitor network performance metrics to determine if adjustments are necessary.
  3. Test thoroughly with various network conditions to ensure optimal performance.
  4. Consider the trade-offs between packet order correction and potential increased latency.

Regarding the associated variable CVarNetPacketOrderCorrectionEnableThreshold:

The purpose of CVarNetPacketOrderCorrectionEnableThreshold is identical to net.PacketOrderCorrectionEnableThreshold. It’s the C++ representation of the console variable in the engine’s code.

This variable is used directly in the UNetConnection::ReceivedPacket function to determine when to enable packet order correction. It’s compared against a counter of total out-of-order packets lost to decide whether to enable the correction mechanism.

The value of this variable is set through the TAutoConsoleVariable template, which allows it to be modified at runtime.

CVarNetPacketOrderCorrectionEnableThreshold interacts closely with other networking variables like CVarNetDoPacketOrderCorrection and CVarNetPacketOrderMaxCachedPackets.

Developers should be aware that this variable is used in critical networking code and changes to its value can significantly impact network behavior.

Best practices for using CVarNetPacketOrderCorrectionEnableThreshold include:

  1. Use it in conjunction with other network-related variables for a comprehensive network tuning strategy.
  2. Consider logging or telemetry to track how often the threshold is reached in real-world scenarios.
  3. Be cautious when modifying this value in production environments, as it can affect all network connections.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

	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,
	TEXT("The maximum number of missed packet sequences that is allowed, before treating missing packets as lost."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderMaxCachedPackets(TEXT("net.PacketOrderMaxCachedPackets"), 32,

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	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,
	TEXT("The maximum number of missed packet sequences that is allowed, before treating missing packets as lost."));

static TAutoConsoleVariable<int32> CVarNetPacketOrderMaxCachedPackets(TEXT("net.PacketOrderMaxCachedPackets"), 32,

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

Scope (from outer to inner):

file
function     void UNetConnection::ReceivedPacket

Source code excerpt:

			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);

					int32 CacheSize = FMath::RoundUpToPowerOfTwo(CVarNetPacketOrderMaxCachedPackets.GetValueOnAnyThread());