net.PacketOrderMaxMissingPackets

net.PacketOrderMaxMissingPackets

#Overview

name: net.PacketOrderMaxMissingPackets

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.PacketOrderMaxMissingPackets is to define the maximum number of missed packet sequences that are allowed before treating missing packets as lost in the networking system of Unreal Engine 5.

This setting variable is primarily used by the networking subsystem of Unreal Engine, specifically within the packet handling and ordering mechanism. Based on the callsites, it’s clear that this variable is utilized in the Engine module, particularly in the NetConnection component.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 3, but can be changed at runtime or through configuration files.

The variable interacts closely with the packet ordering system. It’s used in conjunction with other variables like net.PacketOrderMaxCachedPackets to determine how to handle out-of-order or missing packets in the network stream.

Developers must be aware that this variable directly impacts how the engine handles network packet loss and reordering. Setting it too high might introduce unnecessary latency as the engine waits for missing packets, while setting it too low might cause the engine to prematurely treat packets as lost, potentially leading to data loss or inconsistencies.

Best practices when using this variable include:

  1. Carefully tuning it based on the specific network conditions of your game.
  2. Testing thoroughly with various network conditions to ensure optimal performance.
  3. Considering the trade-offs between waiting for out-of-order packets and introducing latency.

Regarding the associated variable CVarNetPacketOrderMaxMissingPackets:

This is the actual C++ variable that corresponds to the net.PacketOrderMaxMissingPackets console variable. It’s used internally by the engine to access the current value of the setting.

The purpose of CVarNetPacketOrderMaxMissingPackets is to provide a programmatic way to access and modify the net.PacketOrderMaxMissingPackets setting within the C++ code.

This variable is used directly in the networking code, specifically in the UNetConnection::ReceivedPacket function. It’s accessed using the GetValueOnAnyThread() method, which suggests that it can be safely read from multiple threads.

Developers should be aware that changes to this CVar will directly affect the behavior of the packet ordering system. It’s important to ensure that any modifications to this value are done carefully and with consideration for the potential impacts on network performance and stability.

Best practices for using CVarNetPacketOrderMaxMissingPackets include:

  1. Using it for runtime adjustments of the packet ordering behavior, if needed.
  2. Monitoring its value in debugging scenarios to understand the current packet ordering settings.
  3. Considering exposing it as a configurable option for advanced users or server administrators, if appropriate for your game.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

	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,
	TEXT("(NOTE: Must be power of 2!) The maximum number of packets to cache while waiting for missing packet sequences, before treating missing packets as lost."));

#if !UE_BUILD_SHIPPING

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	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,
	TEXT("(NOTE: Must be power of 2!) The maximum number of packets to cache while waiting for missing packet sequences, before treating missing packets as lost."));

#if !UE_BUILD_SHIPPING

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

Scope (from outer to inner):

file
function     void UNetConnection::ReceivedPacket

Source code excerpt:

			const bool bCheckForMissingSequence = bPacketOrderCacheActive && PacketOrderCacheCount == 0;
			const bool bFillingPacketOrderCache = bPacketOrderCacheActive && PacketOrderCacheCount > 0;
			const int32 MaxMissingPackets = (bCheckForMissingSequence ? CVarNetPacketOrderMaxMissingPackets.GetValueOnAnyThread() : 0);

			const int32 MissingPacketCount = PacketSequenceDelta - 1;

			// Cache the packet if we are already caching, and begin caching if we just encountered a missing sequence, within range
			if (bFillingPacketOrderCache || (bCheckForMissingSequence && MissingPacketCount > 0 && MissingPacketCount <= MaxMissingPackets))
			{