NetEmulation.PktIncomingLagMax
NetEmulation.PktIncomingLagMax
#Overview
name: NetEmulation.PktIncomingLagMax
This variable is created as a Console Variable (cvar).
- type:
Cmd
- help:
Sets maximum incoming packet latency
It is referenced in 9
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of NetEmulation.PktIncomingLagMax
is to set the maximum incoming packet latency for network emulation in Unreal Engine 5. This setting is part of the network simulation system, which allows developers to test their games under various network conditions.
This variable is primarily used in the networking subsystem of Unreal Engine, specifically in the NetDriver and NetConnection modules. It’s part of the FPacketSimulationSettings
struct, which is used to configure network emulation settings.
The value of this variable is typically set through configuration files, console commands, or programmatically in the engine’s network simulation code. It can be modified at runtime using console commands or through the Level Editor Play settings for network emulation.
This variable interacts closely with PktIncomingLagMin
. Together, they define a range for simulating incoming packet latency. The actual latency applied to incoming packets will be randomly chosen between these two values.
Developers should be aware that:
- This setting only affects incoming packets, not outgoing ones.
- It’s used in conjunction with
PktIncomingLagMin
to create a range of possible latencies. - Setting this value too high might severely impact gameplay and testing, so it should be used judiciously.
Best practices when using this variable include:
- Always ensure that
PktIncomingLagMax
is greater than or equal toPktIncomingLagMin
. - Use realistic values that represent actual network conditions you expect your game to encounter.
- Test your game with various latency settings to ensure it performs well under different network conditions.
Regarding the associated variable PktIncomingLagMax
:
The purpose of PktIncomingLagMax
is the same as NetEmulation.PktIncomingLagMax
. It’s used in the same context and for the same purpose. The NetEmulation.
prefix is likely used in certain parts of the engine to namespace the variable, but they refer to the same setting.
This variable is used in the same subsystems and modules as mentioned earlier. It’s set and accessed in the same ways, through configuration files, console commands, or programmatically.
The same considerations and best practices apply to PktIncomingLagMax
as to NetEmulation.PktIncomingLagMax
. They are essentially the same variable, just referenced differently in different parts of the engine.
#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:355
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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 PktIncomingLagMax
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/Settings/LevelEditorPlayNetworkEmulationSettings.cpp:33
Scope (from outer to inner):
file
namespace NetworkEmulationSettingsHelper
function void ConvertNetDriverSettingsToLevelEditorSettings
Source code excerpt:
}
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:263
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:537
Scope: file
Source code excerpt:
/**
* 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
*/
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.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetEmulationHelper.cpp:352
Scope (from outer to inner):
file
namespace UE::Net::Private::NetEmulationHelper
Source code excerpt:
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:4468
Scope (from outer to inner):
file
function void FPacketSimulationSettings::LoadConfig
Source code excerpt:
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)
{
#if DO_ENABLE_NET_TEST
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4542
Scope (from outer to inner):
file
function void FPacketSimulationSettings::ValidateSettings
Source code excerpt:
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)
{
#if DO_ENABLE_NET_TEST
if (OptionalQualifier)
{
if (GConfig->GetInt(TEXT("PacketSimulationSettings"), *FString::Printf(TEXT("%s%s"), OptionalQualifier, Name), Value, GEngineIni))
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4654
Scope (from outer to inner):
file
function bool FPacketSimulationSettings::ParseSettings
Source code excerpt:
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);
}
if (ParseHelper(Cmd, TEXT("PktJitter="), PktJitter, OptionalQualifier))
{
bParsed = true;
UE_LOG(LogNet, Log, TEXT("PktJitter set to %d"), PktJitter);
}