![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include "Stats/Stats.h"#include "UObject/ObjectMacros.h"#include "UObject/Class.h"#include "Misc/NetworkVersion.h"#include "UObject/CoreNet.h"#include "EngineLogs.h"#include "Net/Core/Serialization/QuantizedVectorSerialization.h"#include <type_traits>#include "NetSerialization.generated.h"Go to the source code of this file.
Namespaces | |
| namespace | UE |
| namespace | UE::Net |
| namespace | UE::Net::Private |
| bool NetSerializeOptionalValue | ( | const bool | bIsSaving, |
| FArchive & | Ar, | ||
| ValueType & | Value, | ||
| const ValueType & | DefaultValue, | ||
| class UPackageMap * | PackageMap | ||
| ) |
Helper to optionally serialize a value (using the NetSerialize function). A single signal bit indicates whether to serialize, or whether to just use the default value. Returns true if the value was not the default and needed to be serialized.
| int32 SafeNetSerializeTArray_HeaderOnly | ( | FArchive & | Ar, |
| TArray< T, A > & | Array, | ||
| bool & | bOutSuccess | ||
| ) |
===================== Safe TArray Serialization =====================
These are helper methods intended to make serializing TArrays safer in custom ::NetSerialize functions. These enforce max limits on array size, so that a malformed packet is not able to allocate an arbitrary amount of memory (E.g., a hacker serilizes a packet where a TArray size is of size MAX_int32, causing gigs of memory to be allocated for the TArray).
These should only need to be used when you are overriding ::NetSerialize on a UStruct via struct traits. When using default replication, TArray properties already have this built in security.
SafeNetSerializeTArray_Default - calls << operator to serialize the items in the array. SafeNetSerializeTArray_WithNetSerialize - calls NetSerialize to serialize the items in the array.
When saving, bOutSuccess will be set to false if the passed in array size exceeds to MaxNum template parameter.
Example:
FMyStruct {
TArray<float> MyFloats; // We want to call << to serialize floats
TArray<FVector_NetQuantizeNormal> MyVectors; // We want to call NetSeriailze on these *
bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess)
{
// Don't do this:
Ar << MyFloats;
Ar << MyVectors;
// Do this instead:
SafeNetSerializeTArray_Default<31>(Ar, MyFloats);
SafeNetSerializeTArray_WithNetSerialize<31>(Ar, MyVectors, Map);
}
}
| bool SafeNetSerializeTArray_WithNetSerialize | ( | FArchive & | Ar, |
| TArray< T, A > & | Array, | ||
| class UPackageMap * | PackageMap | ||
| ) |
| bool SerializeOptionalValue | ( | const bool | bIsSaving, |
| FArchive & | Ar, | ||
| ValueType & | Value, | ||
| const ValueType & | DefaultValue | ||
| ) |
Helper to optionally serialize a value (using operator<< on Archive). A single signal bit is indicates whether to serialize, or whether to just use the default value. Returns true if the value was not the default and needed to be serialized.