net.MaxNetStringSize
net.MaxNetStringSize
#Overview
name: net.MaxNetStringSize
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Maximum allowed size for strings sent/received by the netcode (in bytes).
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of net.MaxNetStringSize is to set the maximum allowed size for strings sent and received by the netcode in Unreal Engine 5. This setting is crucial for managing network communication and serialization in the engine.
This setting variable is primarily used by the Core module of Unreal Engine, specifically in the serialization and networking subsystems. Based on the callsites provided, it’s evident that the BitArchive and BitWriter components of the serialization system rely on this setting.
The value of this variable is set through a console variable (CVar) named CVarMaxNetStringSize. It’s initialized with a default value of 16 * 1024 * 1024 bytes (16 MB) and can be changed at runtime through console commands or configuration files.
The associated variable CVarMaxNetStringSize interacts directly with net.MaxNetStringSize. It’s a TAutoConsoleVariable
Developers must be aware of several important aspects when using this variable:
-
This setting directly affects network performance and security. Setting it too high might lead to potential exploitation or performance issues, while setting it too low might cause legitimate data to be truncated.
-
Changes to this value will affect all network serialization operations that involve strings.
-
The value is used to initialize the ArMaxSerializeSize member of FBitArchive and FBitWriter classes, which are fundamental to Unreal Engine’s serialization system.
Best practices when using this variable include:
-
Carefully consider the needs of your project when adjusting this value. Don’t set it higher than necessary.
-
Monitor network traffic and adjust the value based on actual usage patterns in your game.
-
Consider implementing additional checks or compression for large string data to minimize the risk of network-related issues.
-
When modifying this value, test thoroughly to ensure it doesn’t negatively impact game performance or stability.
-
Document any changes to this value in your project settings to ensure all team members are aware of the current configuration.
Regarding the associated variable CVarMaxNetStringSize:
The purpose of CVarMaxNetStringSize is to provide a runtime-configurable way to set and access the net.MaxNetStringSize value. It’s a console variable that allows for easy modification of the setting during development and debugging.
This variable is used in the Core module, specifically in the serialization system. It’s accessed in the FBitArchive and FBitWriter classes to set their maximum serialization size.
The value of CVarMaxNetStringSize is set when it’s declared, but it can be modified at runtime through console commands.
Developers should be aware that changes to CVarMaxNetStringSize will immediately affect all new FBitArchive and FBitWriter instances created after the change. Existing instances won’t be automatically updated.
Best practices for using CVarMaxNetStringSize include:
-
Use GetValueOnAnyThread() when accessing the value to ensure thread-safety.
-
Consider adding logging or notifications when this value is changed to help with debugging.
-
If your game requires a specific range of values, consider implementing additional checks when setting this variable to ensure it remains within acceptable bounds.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Serialization/BitArchive.cpp:6
Scope: file
Source code excerpt:
// Globals
CORE_API TAutoConsoleVariable<int32> CVarMaxNetStringSize(TEXT("net.MaxNetStringSize"), 16 * 1024 * 1024, TEXT("Maximum allowed size for strings sent/received by the netcode (in bytes)."));
FBitArchive::FBitArchive()
{
ArMaxSerializeSize = CVarMaxNetStringSize.GetValueOnAnyThread();
}
#Associated Variable and Callsites
This variable is associated with another variable named CVarMaxNetStringSize
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Serialization/BitArchive.cpp:6
Scope: file
Source code excerpt:
// Globals
CORE_API TAutoConsoleVariable<int32> CVarMaxNetStringSize(TEXT("net.MaxNetStringSize"), 16 * 1024 * 1024, TEXT("Maximum allowed size for strings sent/received by the netcode (in bytes)."));
FBitArchive::FBitArchive()
{
ArMaxSerializeSize = CVarMaxNetStringSize.GetValueOnAnyThread();
}
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Serialization/BitWriter.cpp:11
Scope: file
Source code excerpt:
/** CVar specifying the maximum serialization size for strings sent/received by the netcode */
extern CORE_API TAutoConsoleVariable<int32> CVarMaxNetStringSize;
PRAGMA_DISABLE_UNSAFE_TYPECAST_WARNINGS
extern const uint8 GShift[8];
extern const uint8 GMask[8];
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Serialization/BitWriter.cpp:72
Scope (from outer to inner):
file
function void FBitWriter::Reset
Source code excerpt:
// This class is exclusively used by the netcode
ArIsNetArchive = true;
ArMaxSerializeSize = CVarMaxNetStringSize.GetValueOnAnyThread();
}
void FBitWriter::SerializeBits( void* Src, int64 LengthBits )
{
if( AllowAppend(LengthBits) )
{