NetEmulation.PktLagMax
NetEmulation.PktLagMax
#Overview
name: NetEmulation.PktLagMax
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Sets maximum outgoing packet latency)
It is referenced in 9
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktLagMax is to set the maximum outgoing packet latency for network emulation in Unreal Engine 5. This variable is part of the network emulation system, which allows developers to simulate various network conditions for testing and debugging purposes.
NetEmulation.PktLagMax is primarily used by the networking subsystem of Unreal Engine 5, specifically within the NetDriver and NetConnection modules. It is also utilized by the LevelEditorPlayNetworkEmulationSettings for configuring network emulation in the editor.
The value of this variable is typically set through various methods:
- Console commands (as seen in NetEmulationHelper.cpp)
- Configuration files (loaded via FPacketSimulationSettings::LoadConfig)
- Editor settings (in LevelEditorPlayNetworkEmulationSettings)
NetEmulation.PktLagMax interacts closely with NetEmulation.PktLagMin. Together, they define a range for the outgoing packet latency. The actual latency applied to each packet is randomly selected between these two values.
Developers should be aware of the following when using this variable:
- It works in conjunction with PktLagMin to create a latency range.
- The value is in milliseconds.
- It is only applied to outgoing packets.
- If both PktLag and PktLagMax/Min are set, the PktLag value takes precedence.
Best practices for using this variable include:
- Always set both PktLagMin and PktLagMax for a realistic latency simulation.
- Ensure PktLagMax is greater than or equal to PktLagMin.
- Use reasonable values that reflect real-world network conditions you want to test.
- Remember to disable or reset these values when not testing network conditions.
Regarding the associated variable PktLagMax:
The purpose of PktLagMax is the same as NetEmulation.PktLagMax. It’s used within the engine’s internal structures to store and apply the maximum outgoing packet latency setting.
PktLagMax is used in various parts of the engine, including:
- NetDriver for storing packet simulation settings
- NetConnection for applying the simulated latency to outgoing packets
- LevelEditorPlayNetworkEmulationSettings for configuring network emulation in the editor
The value of PktLagMax is set through the same methods as NetEmulation.PktLagMax, and they are essentially two representations of the same setting in different contexts.
PktLagMax interacts with PktLagMin, PktLag, and other packet simulation settings within the FPacketSimulationSettings structure.
Developers should be aware that PktLagMax is clamped to be at least equal to PktLagMin during validation.
Best practices for PktLagMax are the same as those for NetEmulation.PktLagMax, emphasizing the importance of setting realistic values and using it in conjunction with PktLagMin for effective network condition simulation.
#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:353
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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");
#Associated Variable and Callsites
This variable is associated with another variable named PktLagMax
. They share the same value. See 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);
}