PktLagMin
PktLagMin
#Overview
name: PktLagMin
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 10
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of PktLagMin is to set the minimum outgoing packet latency in network simulation settings for Unreal Engine 5. It is part of the network emulation system used to simulate various network conditions during development and testing.
This setting variable is primarily used in the networking subsystem of Unreal Engine, specifically in the NetDriver and NetConnection modules. It’s utilized for network emulation and packet simulation, which are crucial for testing multiplayer game scenarios under different network conditions.
The value of PktLagMin is typically set through configuration files (.ini) or can be modified at runtime using console commands. It interacts closely with other network simulation variables such as PktLagMax, PktLag, and PktLagVariance.
Developers should be aware that:
- PktLagMin sets a lower bound for outgoing packet latency.
- It works in conjunction with PktLagMax to create a range of possible latencies.
- If PktLag is set, it takes precedence over PktLagMin and PktLagMax.
Best practices when using this variable include:
- Always ensure PktLagMin is non-negative.
- Set PktLagMin lower than or equal to PktLagMax.
- Use in combination with other network simulation settings for comprehensive testing.
- Adjust values to simulate various network conditions relevant to your target audience.
- Remember to disable or reset these settings before shipping the game.
By manipulating PktLagMin along with other network simulation settings, developers can create realistic network scenarios to test their game’s performance and behavior under different network conditions.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:3268, section: [PacketSimulationProfile.Off]
- INI Section:
PacketSimulationProfile.Off
- Raw value:
0
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseEngine.ini:3277, section: [PacketSimulationProfile.Average]
- INI Section:
PacketSimulationProfile.Average
- Raw value:
30
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseEngine.ini:3286, section: [PacketSimulationProfile.Bad]
- INI Section:
PacketSimulationProfile.Bad
- Raw value:
100
- 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:259
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
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:521
Scope: file
Source code excerpt:
/**
* 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.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLagMin = 0;
/**
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:547
Scope: file
Source code excerpt:
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLoss = 0;
/**
* Causes sent packets to have a variable latency that fluctuates from [PktLagMin] to [PktLagMin+PktJitter]
* Note that this will cause packet loss on the receiving end.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktJitter = 0;
/** reads in settings from the .ini file
* @note: overwrites all previous settings
*/
ENGINE_API void LoadConfig(const TCHAR* OptionalQualifier = nullptr);
/**
* Load a preconfigured emulation profile from the .ini
* Returns true if the given profile existed
*/
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:349
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");
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:2329
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
if (bIsLowLatency)
{
// ExtraLag goes from [PktLagMin, PktLagMin+PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
}
else
{
// ExtraLag goes from [PktLagMin+PktJitter, PktLagMin+PktJitter+PktLagVariance]
const double LagVariance = 2.0f * (FMath::FRand() - 0.5f) * double(PacketSimulationSettings.PktLagVariance);
const double ExtraLag = (double(PacketSimulationSettings.PktLagMin + PacketSimulationSettings.PktJitter) + LagVariance) / 1000.f;
B.SendTime = FPlatformTime::Seconds() + ExtraLag;
}
}
else if (PacketSimulationSettings.PktLag)
{
FDelayedPacket& B = *(new(Delayed)FDelayedPacket(SendBuffer.GetData(), SendBuffer.GetNumBits(), Traits));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2354
Scope (from outer to inner):
file
function bool UNetConnection::CheckOutgoingPacketEmulation
Source code excerpt:
}
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;
#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);
ConfigHelperInt(TEXT("PktIncomingLagMin"), PktIncomingLagMin, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLagMax"), PktIncomingLagMax, OptionalQualifier);
ConfigHelperInt(TEXT("PktIncomingLoss"), PktIncomingLoss, OptionalQualifier);
ConfigHelperInt(TEXT("PktJitter"), PktJitter, OptionalQualifier);
ValidateSettings();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4536
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
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);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4639
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
if (ParseHelper(Cmd, TEXT("PktLagVariance="), PktLagVariance, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktLagVariance set to %d"), PktLagVariance);
}
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);
}