NetEmulation.PktIncomingLagMin
NetEmulation.PktIncomingLagMin
#Overview
name: NetEmulation.PktIncomingLagMin
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Sets minimum incoming packet latency
It is referenced in 9
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktIncomingLagMin is to set the minimum incoming 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.
This setting variable is primarily used by the networking subsystem of Unreal Engine, specifically in the network emulation and packet simulation features. It’s referenced in the Engine module, particularly in the NetDriver and NetConnection classes.
The value of this variable is set through various means:
- It can be configured in the project settings.
- It can be set via console commands during runtime.
- It’s also used in the LevelEditorPlayNetworkEmulationSettings, allowing developers to set network emulation parameters for Play-in-Editor sessions.
NetEmulation.PktIncomingLagMin interacts with several other variables, most notably:
- NetEmulation.PktIncomingLagMax: Together, these define the range of incoming packet latency.
- Other network emulation settings like PktIncomingLoss, PktLagMin, PktLagMax, etc.
Developers should be aware of the following when using this variable:
- It’s used in conjunction with PktIncomingLagMax to create a range of latency.
- The value is clamped to be non-negative in the ValidateSettings function.
- It affects incoming packets only, not outgoing ones.
Best practices for using this variable include:
- Use it in combination with other network emulation settings for comprehensive network condition simulation.
- Ensure PktIncomingLagMin is always less than or equal to PktIncomingLagMax.
- Use it during development and testing phases to simulate various network conditions, but disable it for production builds.
Regarding the associated variable PktIncomingLagMin:
The purpose of PktIncomingLagMin is the same as NetEmulation.PktIncomingLagMin. It’s used in the FPacketSimulationSettings struct within the UNetDriver class to store the minimum incoming packet latency for network simulation.
This variable is used directly in the network subsystem, particularly in the ReceivedPacket function of UNetConnection. It’s set through the LoadConfig function of FPacketSimulationSettings and can be parsed from command-line arguments.
PktIncomingLagMin interacts closely with PktIncomingLagMax to define the range of simulated incoming packet latency.
Developers should be aware that this variable is used in actual packet processing logic, adding artificial delay to incoming packets when network emulation is enabled.
Best practices for PktIncomingLagMin are similar to those for NetEmulation.PktIncomingLagMin, emphasizing its use in testing and development environments and ensuring it’s properly configured in relation to PktIncomingLagMax.
#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:354
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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
#Associated Variable and Callsites
This variable is associated with another variable named PktIncomingLagMin
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:32
Scope (from outer to inner):
file
namespace NetworkEmulationSettingsHelper
function void ConvertNetDriverSettingsToLevelEditorSettings
Source code excerpt:
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)
{
void* ValueData(nullptr);
FPropertyAccess::Result Result = PropertyHandle->GetValueData(ValueData);
if (Result != FPropertyAccess::Success)
{
return nullptr;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:262
Scope (from outer to inner):
file
function void FLevelEditorPlayNetworkEmulationSettings::ConvertToNetDriverSettings
Source code excerpt:
{
// 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)
{
return FString();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:530
Scope: file
Source code excerpt:
/**
* 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.
*/
UPROPERTY(EditAnywhere, Category = "Simulation Settings")
int32 PktIncomingLagMax = 0;
/**
* The ratio of incoming packets that will be dropped
* to simulate packet loss
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:351
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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:2808
Scope (from outer to inner):
file
function void UNetConnection::ReceivedPacket
Source code excerpt:
UE_LOG(LogNet, VeryVerbose, TEXT("Dropped incoming packet at %f"), FPlatformTime::Seconds());
return;
}
}
if (PacketSimulationSettings.PktIncomingLagMin > 0 || PacketSimulationSettings.PktIncomingLagMax > 0)
{
// ExtraLagInSec goes from [PktIncomingLagMin, PktIncomingLagMax]
const double LagVarianceInMS = FMath::FRand() * double(PacketSimulationSettings.PktIncomingLagMax - PacketSimulationSettings.PktIncomingLagMin);
const double ExtraLagInSec = (double(PacketSimulationSettings.PktIncomingLagMin) + LagVarianceInMS) / 1000.f;
FDelayedIncomingPacket DelayedPacket;
DelayedPacket.PacketData = MakeUnique<FBitReader>(Reader);
DelayedPacket.ReinjectionTime = FPlatformTime::Seconds() + ExtraLagInSec;
DelayedIncomingPackets.Emplace(MoveTemp(DelayedPacket));
UE_LOG(LogNet, VeryVerbose, TEXT("Delaying incoming packet for %f seconds"), ExtraLagInSec);
return;
}
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4467
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
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
}
bool FPacketSimulationSettings::LoadEmulationProfile(const TCHAR* ProfileName)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4541
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
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:4649
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
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);
}
if (ParseHelper(Cmd, TEXT("PktIncomingLoss="), PktIncomingLoss, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktIncomingLoss set to %d"), PktIncomingLoss);
}