net.PacketOrderMaxCachedPackets
net.PacketOrderMaxCachedPackets
#Overview
name: net.PacketOrderMaxCachedPackets
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
(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.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.PacketOrderMaxCachedPackets is to control the maximum number of packets that can be cached while waiting for missing packet sequences in the networking system of Unreal Engine 5. This setting is crucial for managing network packet ordering and handling out-of-order packet arrivals.
This setting variable is primarily used in the networking subsystem of Unreal Engine, specifically within the UNetConnection class. It’s referenced in the Engine module, in the file NetConnection.cpp.
The value of this variable is set as a console variable with a default value of 32. It can be modified at runtime through the console or configuration files.
The associated variable CVarNetPacketOrderMaxCachedPackets interacts directly with net.PacketOrderMaxCachedPackets. They share the same value and purpose.
Developers must be aware of several important aspects when using this variable:
- The value must be a power of 2, as stated in the comment.
- It directly affects network performance and memory usage.
- Changing this value impacts how the engine handles out-of-order packets.
Best practices for using this variable include:
- Only modify if you have a good understanding of the networking system.
- Monitor network performance when adjusting this value.
- Consider the trade-off between packet ordering correctness and memory usage.
- Test thoroughly in various network conditions after making changes.
Regarding the associated variable CVarNetPacketOrderMaxCachedPackets:
- It’s an internal representation of the console variable.
- It’s used directly in the code to retrieve the current value of the setting.
- The value is rounded up to the nearest power of two before being used to initialize the PacketOrderCache.
- Developers should be aware that changes to the console variable will be reflected through this associated variable in the code.
When working with both variables, ensure consistency between the console variable and any hard-coded references to CVarNetPacketOrderMaxCachedPackets in the codebase.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:90
Scope: file
Source code excerpt:
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
static TAutoConsoleVariable<int32> CVarDisableBandwithThrottling(TEXT("net.DisableBandwithThrottling"), 0,
TEXT("Forces IsNetReady to always return true. Not available in shipping builds."));
#endif
#Associated Variable and Callsites
This variable is associated with another variable named CVarNetPacketOrderMaxCachedPackets
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:90
Scope: file
Source code excerpt:
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
static TAutoConsoleVariable<int32> CVarDisableBandwithThrottling(TEXT("net.DisableBandwithThrottling"), 0,
TEXT("Forces IsNetReady to always return true. Not available in shipping builds."));
#endif
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:3032
Scope (from outer to inner):
file
function void UNetConnection::ReceivedPacket
Source code excerpt:
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());
PacketOrderCache.Emplace(CacheSize);
}
}
// Protect against replay attacks