NetEmulation.PktLag
NetEmulation.PktLag
#Overview
name: NetEmulation.PktLag
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Simulates network packet lag
It is referenced in 9
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktLag is to simulate network packet lag in Unreal Engine’s networking system. This setting variable is part of the network emulation features that allow developers to test their games under various network conditions.
NetEmulation.PktLag is primarily used by the networking subsystem of Unreal Engine, specifically within the NetDriver and NetConnection modules. These modules are responsible for managing network communications in multiplayer games.
The value of this variable is typically set through configuration files, console commands, or programmatically in code. It can be modified during runtime using the console command “PktLag” as seen in the NetEmulationHelper.cpp file.
PktLag interacts with several other variables, including:
- PktLagVariance: Used to add randomness to the simulated lag.
- PktLagMin and PktLagMax: Used to set a range for the lag when PktLag is not directly set.
- PktOrder and PktDup: Other network simulation settings that cannot be used simultaneously with PktLag.
Developers should be aware of the following when using this variable:
- PktLag is measured in milliseconds.
- It cannot be used simultaneously with PktOrder.
- When PktLag is set, it takes precedence over PktLagMin and PktLagMax.
- The actual lag applied can vary based on the PktLagVariance setting.
Best practices for using this variable include:
- Use it in conjunction with other network simulation settings to create realistic test scenarios.
- Be cautious when setting high values, as they may significantly impact gameplay.
- Remember to disable or reset these settings before releasing the game.
The associated variable PktLag serves the same purpose as NetEmulation.PktLag. It’s used within the PacketSimulationSettings struct, which is part of the NetConnection and NetDriver classes. This variable is directly manipulated when applying network simulation settings and is used in the actual packet delay calculations. The same considerations and best practices apply to this associated variable.
#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:350
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
#Associated Variable and Callsites
This variable is associated with another variable named PktLag
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:22
Scope (from outer to inner):
file
namespace NetworkEmulationSettingsHelper
function void ConvertNetDriverSettingsToLevelEditorSettings
Source code excerpt:
void ConvertNetDriverSettingsToLevelEditorSettings(const FPacketSimulationSettings& NetDriverSettings, FNetworkEmulationPacketSettings& OutgoingTrafficPieSettings, FNetworkEmulationPacketSettings& IncomingTrafficPieSettings)
{
if (NetDriverSettings.PktLag > 0)
{
OutgoingTrafficPieSettings.MinLatency = FMath::Max(NetDriverSettings.PktLag - NetDriverSettings.PktLagVariance, 0);
OutgoingTrafficPieSettings.MaxLatency = FMath::Max(OutgoingTrafficPieSettings.MinLatency, NetDriverSettings.PktLag + NetDriverSettings.PktLagVariance); ;
}
else if (NetDriverSettings.PktLagMin > 0 || NetDriverSettings.PktLagMax > 0)
{
OutgoingTrafficPieSettings.MinLatency = NetDriverSettings.PktLagMin;
OutgoingTrafficPieSettings.MaxLatency = NetDriverSettings.PktLagMax;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetConnection.h:1897
Scope (from outer to inner):
file
function FNetConnectionSettings
Source code excerpt:
{
#if DO_ENABLE_NET_TEST
PacketLag = InConnection->PacketSimulationSettings.PktLag;
#else
PacketLag = 0;
#endif
}
FNetConnectionSettings( int32 InPacketLag )
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetConnection.h:1911
Scope (from outer to inner):
file
function void ApplyTo
Source code excerpt:
{
#if DO_ENABLE_NET_TEST
Connection->PacketSimulationSettings.PktLag = PacketLag;
#endif
}
int32 PacketLag;
};
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:485
Scope: file
Source code excerpt:
* This works by randomly selecting packets to be delayed until a subsequent call to FlushNet.
*
* Takes precedence over PktDup and PktLag.
*/
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")
int32 PktLagVariance = 0;
/**
* If set lag values will randomly fluctuate between Min and Max.
* Ignored if PktLag value is set
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktLagMin = 0;
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktLagMax = 0;
/**
* Set a value to add a minimum delay in milliseconds to incoming
* packets before they are processed.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:350
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLagMax, "Sets maximum incoming packet latency");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktIncomingLoss, "Simulates incoming packet loss");
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2345
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
}
}
else if (PacketSimulationSettings.PktLag)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
// ExtraLag goes from PktLag + [-PktLagVariance, PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLag) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
return true;
}
else if (PacketSimulationSettings.PktLagMin > 0 || PacketSimulationSettings.PktLagMax > 0)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4462
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
PktOrder = int32(InPktOrder);
ConfigHelperInt(TEXT("PktLag"), PktLag, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagVariance"), PktLagVariance, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagMin"), PktLagMin, OptionalQualifier);
ConfigHelperInt(TEXT("PktLagMax"), PktLagMax, OptionalQualifier);
ConfigHelperInt(TEXT("PktDup"), PktDup, OptionalQualifier);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4627
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
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);
}
if( ParseHelper(Cmd, TEXT("PktDup="), PktDup, OptionalQualifier) )
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktDup set to %d"), PktDup);
}