PktLagMax
PktLagMax
#Overview
name: PktLagMax
The value of this variable can be defined or overridden in .ini config files. 3
.ini config files referencing this setting variable.
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of PktLagMax is to simulate network conditions by setting the maximum outgoing packet latency in a networked game environment. This variable is part of the network simulation settings in Unreal Engine 5, specifically designed for testing and debugging network-related issues.
PktLagMax is primarily used by the networking subsystem of Unreal Engine, particularly in the NetDriver and NetConnection modules. It’s also utilized in the LevelEditorPlayNetworkEmulationSettings for configuring network emulation during Play-in-Editor sessions.
The value of this variable is typically set through configuration files, console commands, or programmatically within the engine. It can be loaded from config files using the LoadConfig function in FPacketSimulationSettings, or set via console commands as seen in the NetEmulationHelper.
PktLagMax interacts closely with PktLagMin to define a range of latency for outgoing packets. It’s also related to other network simulation variables like PktLag, PktLagVariance, and various incoming packet settings.
Developers should be aware that:
- PktLagMax must be greater than or equal to PktLagMin.
- It’s used in conjunction with PktLagMin to create a range of latency, where the actual latency is randomly selected within this range.
- The value is in milliseconds.
Best practices when using this variable include:
- Always set it in conjunction with PktLagMin for realistic network simulation.
- Use it for testing worst-case scenarios in your networked game.
- Remember to disable or reset these values in production builds.
- Use in combination with other network simulation settings for comprehensive testing.
- Validate the settings to ensure they’re within acceptable ranges, as done in the ValidateSettings function.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:3269, section: [PacketSimulationProfile.Off]
- INI Section:
PacketSimulationProfile.Off
- Raw value:
0
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseEngine.ini:3278, section: [PacketSimulationProfile.Average]
- INI Section:
PacketSimulationProfile.Average
- Raw value:
60
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseEngine.ini:3287, section: [PacketSimulationProfile.Bad]
- INI Section:
PacketSimulationProfile.Bad
- Raw value:
200
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:24
Scope (from outer to inner):
file
namespace NetworkEmulationSettingsHelper
function void ConvertNetDriverSettingsToLevelEditorSettings
Source code excerpt:
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;
}
OutgoingTrafficPieSettings.PacketLossPercentage = NetDriverSettings.PktLoss;
IncomingTrafficPieSettings.MinLatency = NetDriverSettings.PktIncomingLagMin;
IncomingTrafficPieSettings.MaxLatency = NetDriverSettings.PktIncomingLagMax;
IncomingTrafficPieSettings.PacketLossPercentage = NetDriverSettings.PktIncomingLoss;
}
FNetworkEmulationPacketSettings* GetPacketSettingsFromHandle(const TSharedPtr<IPropertyHandle>& PropertyHandle)
{
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:260
Scope (from outer to inner):
file
function void FLevelEditorPlayNetworkEmulationSettings::ConvertToNetDriverSettings
Source code excerpt:
if (IsCustomProfile() || !bProfileFound)
{
// For custom set the settings manually from the PIE variables
OutNetDriverSettings.PktLagMin = OutPackets.MinLatency;
OutNetDriverSettings.PktLagMax = OutPackets.MaxLatency;
OutNetDriverSettings.PktLoss = OutPackets.PacketLossPercentage;
OutNetDriverSettings.PktIncomingLagMin = InPackets.MinLatency;
OutNetDriverSettings.PktIncomingLagMax = InPackets.MaxLatency;
OutNetDriverSettings.PktIncomingLoss = InPackets.PacketLossPercentage;
}
}
FString FLevelEditorPlayNetworkEmulationSettings::BuildPacketSettingsForCmdLine() const
{
// Empty string when disabled
if (!bIsNetworkEmulationEnabled)
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:523
Scope: file
Source code excerpt:
* 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.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLagMin = 0;
/**
* The maximum delay in milliseconds to add 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");
BUILD_NETEMULATION_CONSOLE_COMMAND(PktJitter, "Simulates outgoing packet jitter");
} // end namespace UE::Net::Private::NetEmulationHelper
#endif //#if DO_ENABLE_NET_TEST
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2354
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
return true;
}
else if (PacketSimulationSettings.PktLagMin > 0 || PacketSimulationSettings.PktLagMax > 0)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
// ExtraLag goes from [PktLagMin, PktLagMax]
const double LagVariance = FMath::FRand() * double(PacketSimulationSettings.PktLagMax - PacketSimulationSettings.PktLagMin);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
return true;
}
return false;
}
#endif
#if DO_ENABLE_NET_TEST
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4463
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
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);
ConfigHelperInt(TEXT("PktIncomingLagMin"), PktIncomingLagMin, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLagMax"), PktIncomingLagMax, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLoss"), PktIncomingLoss, OptionalQualifier);
ConfigHelperInt(TEXT("PktJitter"), PktJitter, OptionalQualifier);
ValidateSettings();
#endif
#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);
PktIncomingLagMin = FMath::Max(PktIncomingLagMin, 0);
PktIncomingLagMax = FMath::Max(PktIncomingLagMin, PktIncomingLagMax);
PktIncomingLoss = FMath::Clamp<int32>(PktIncomingLoss, 0, 100);
#endif
}
bool FPacketSimulationSettings::ConfigHelperInt(const TCHAR* Name, int32& Value, const TCHAR* OptionalQualifier)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4644
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
if (ParseHelper(Cmd, TEXT("PktLagMin="), PktLagMin, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagMin set to %d"), PktLagMin);
}
if (ParseHelper(Cmd, TEXT("PktLagMax="), PktLagMax, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagMax set to %d"), PktLagMax);
}
if (ParseHelper(Cmd, TEXT("PktIncomingLagMin="), PktIncomingLagMin, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktIncomingLagMin set to %d"), PktIncomingLagMin);
}
if (ParseHelper(Cmd, TEXT("PktIncomingLagMax="), PktIncomingLagMax, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktIncomingLagMax set to %d"), PktIncomingLagMax);
}