NetEmulation.PktOrder
NetEmulation.PktOrder
#Overview
name: NetEmulation.PktOrder
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Simulates network packets received out of order
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktOrder is to simulate network packets received out of order in Unreal Engine’s networking system. This setting is part of the network emulation functionality, which is designed to simulate various network conditions for testing and debugging purposes.
NetEmulation.PktOrder is primarily used in the Engine module, specifically within the networking subsystem. The main components that rely on this setting are:
- UNetConnection: Used in packet handling and simulation.
- FPacketSimulationSettings: Manages various network simulation settings.
- UNetDriver: Handles network driver configuration and simulation settings.
The value of this variable is set in multiple ways:
- It can be set through the Engine’s configuration files.
- It can be modified at runtime using console commands.
- It can be adjusted programmatically through the FPacketSimulationSettings struct.
The associated variable PktOrder interacts closely with NetEmulation.PktOrder. They essentially represent the same setting, with PktOrder being the actual property in the FPacketSimulationSettings struct.
Developers should be aware of the following when using this variable:
- It’s a boolean value (0 or 1) that enables or disables out-of-order packet simulation.
- It cannot be used simultaneously with PktLag or PktDup settings.
- When enabled, it affects the order of packet processing in the UNetConnection class.
Best practices for using this variable include:
- Use it only for testing and debugging purposes, not in production builds.
- Combine it with other network simulation settings to create realistic network condition scenarios.
- Always validate and clamp the value to ensure it’s either 0 or 1.
- Be cautious when using it in multiplayer games, as it can significantly affect gameplay and perceived performance.
Regarding the associated variable PktOrder:
- It’s an integer property in the FPacketSimulationSettings struct.
- It’s used to store the actual value of the out-of-order packet simulation setting.
- It’s clamped between 0 and 1 in the ValidateSettings function.
- It can be configured through the Engine’s configuration system using the “PktOrder” key.
- It’s exposed as an editable property in the Unreal Editor, allowing for easy adjustment in the simulation settings.
When working with PktOrder, developers should follow the same best practices and be aware of the same limitations as with NetEmulation.PktOrder. They should also ensure that any changes to PktOrder are properly validated and clamped to maintain consistent behavior across the engine.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:348
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLoss, "Simulates network packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktOrder, "Simulates network packets received out of order");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktDup, "Simulates sending/receiving duplicate network packets");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLag, "Simulates network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagVariance, "Simulates variable network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMin, "Sets minimum outgoing packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMax, "Sets maximum outgoing packet latency)");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMin, "Sets minimum incoming packet latency");
#Associated Variable and Callsites
This variable is associated with another variable named PktOrder
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:488
Scope: file
Source code excerpt:
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
int32 PktOrder = 0;
/**
* When set, will cause calls to FlushNet to duplicate packets.
* Value is treated as % of packets duplicated (i.e. 0 = None, 100 = All).
* No general pattern / ordering is guaranteed.
* Clamped between 0 and 100.
*
* Cannot be used with PktOrder or PktLag.
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
int32 PktDup = 0;
/**
* When set, will cause calls to FlushNet to delay packets.
* Value is treated as millisecond lag.
*
* Cannot be used with PktOrder.
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
int32 PktLag = 0;
/**
* When set, will cause PktLag to use variable lag instead of constant.
* Value is treated as millisecond lag range (e.g. -GivenVariance <= 0 <= GivenVariance).
*
* Can only be used when PktLag is enabled.
*/
UPROPERTY(EditAnywhere, Category="Simulation Settings")
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:348
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLoss, "Simulates network packet loss");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktOrder, "Simulates network packets received out of order");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktDup, "Simulates sending/receiving duplicate network packets");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLag, "Simulates network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagVariance, "Simulates variable network packet lag");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMin, "Sets minimum outgoing packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktLagMax, "Sets maximum outgoing packet latency)");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMin, "Sets minimum incoming packet latency");
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2301
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
return true;
}
else if (PacketSimulationSettings.PktOrder)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
for (int32 i = Delayed.Num() - 1; i >= 0; i--)
{
if (FMath::FRand() > 0.50)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4458
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
ConfigHelperInt(TEXT("PktLossMaxSize"), PktLossMaxSize, OptionalQualifier);
bool InPktOrder = !!PktOrder;
ConfigHelperBool(TEXT("PktOrder"), InPktOrder, OptionalQualifier);
PktOrder = int32(InPktOrder);
ConfigHelperInt(TEXT("PktLag"), PktLag, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagVariance"), PktLagVariance, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagMin"), PktLagMin, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagMax"), PktLagMax, OptionalQualifier);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4537
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
PktLoss = FMath::Clamp<int32>(PktLoss, 0, 100);
PktOrder = FMath::Clamp<int32>(PktOrder, 0, 1);
PktLagMin = FMath::Max(PktLagMin, 0);
PktLagMax = FMath::Max(PktLagMin, PktLagMax);
PktDup = FMath::Clamp<int32>(PktDup, 0, 100);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4622
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
UE_LOG(LogNet, Log, TEXT("PktLossMaxSize set to %d"), PktLossMaxSize);
}
if( ParseHelper(Cmd, TEXT("PktOrder="), PktOrder, OptionalQualifier) )
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktOrder set to %d"), PktOrder);
}
if( ParseHelper(Cmd, TEXT("PktLag="), PktLag, OptionalQualifier) )
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLag set to %d"), PktLag);
}