UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NetSerialization.h File Reference
#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.

Classes

struct  TFixedCompressedFloatDetails< MaxValue, NumBits >
 
struct  FVector_NetQuantize
 
struct  TStructOpsTypeTraits< FVector_NetQuantize >
 
struct  FVector_NetQuantize10
 
struct  TStructOpsTypeTraits< FVector_NetQuantize10 >
 
struct  FVector_NetQuantize100
 
struct  TStructOpsTypeTraits< FVector_NetQuantize100 >
 
struct  FVector_NetQuantizeNormal
 
struct  TStructOpsTypeTraits< FVector_NetQuantizeNormal >
 

Namespaces

namespace  UE
 
namespace  UE::Net
 
namespace  UE::Net::Private
 

Functions

template<typename ValueType >
bool SerializeOptionalValue (const bool bIsSaving, FArchive &Ar, ValueType &Value, const ValueType &DefaultValue)
 
template<typename ValueType >
bool NetSerializeOptionalValue (const bool bIsSaving, FArchive &Ar, ValueType &Value, const ValueType &DefaultValue, class UPackageMap *PackageMap)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool UE::Net::Private::LegacyReadPackedVector (FVector3f &Value, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool WritePackedVector (FVector3f Value, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool WritePackedVector (FVector3d Vector, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool ReadPackedVector (FVector3f &Value, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool ReadPackedVector (FVector3d &Value, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool SerializePackedVector (FVector3f &Value, FArchive &Ar)
 
template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool SerializePackedVector (FVector3d &Value, FArchive &Ar)
 
template<int32 MaxValue, uint32 NumBits, typename T UE_REQUIRES>
bool WriteFixedCompressedFloat (const T Value, FArchive &Ar)
 
template<int32 MaxValue, uint32 NumBits, typename T UE_REQUIRES>
bool ReadFixedCompressedFloat (T &Value, FArchive &Ar)
 
template<int32 MaxValue, uint32 NumBits>
bool SerializeFixedVector (FVector3f &Vector, FArchive &Ar)
 
template<int32 MaxValue, uint32 NumBits>
bool SerializeFixedVector (FVector3d &Vector, FArchive &Ar)
 
template<int32 MaxNum, typename T , typename A >
int32 SafeNetSerializeTArray_HeaderOnly (FArchive &Ar, TArray< T, A > &Array, bool &bOutSuccess)
 
template<int32 MaxNum, typename T , typename A >
bool SafeNetSerializeTArray_Default (FArchive &Ar, TArray< T, A > &Array)
 
template<int32 MaxNum, typename T , typename A >
bool SafeNetSerializeTArray_WithNetSerialize (FArchive &Ar, TArray< T, A > &Array, class UPackageMap *PackageMap)
 

Function Documentation

◆ NetSerializeOptionalValue()

template<typename ValueType >
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.

◆ ReadFixedCompressedFloat()

template<int32 MaxValue, uint32 NumBits, typename T UE_REQUIRES>
bool ReadFixedCompressedFloat ( T &  Value,
FArchive Ar 
)

◆ ReadPackedVector() [1/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool ReadPackedVector ( FVector3d Value,
FArchive Ar 
)

◆ ReadPackedVector() [2/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool ReadPackedVector ( FVector3f Value,
FArchive Ar 
)

◆ SafeNetSerializeTArray_Default()

template<int32 MaxNum, typename T , typename A >
bool SafeNetSerializeTArray_Default ( FArchive Ar,
TArray< T, A > &  Array 
)

◆ SafeNetSerializeTArray_HeaderOnly()

template<int32 MaxNum, typename T , typename A >
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);
}

}

◆ SafeNetSerializeTArray_WithNetSerialize()

template<int32 MaxNum, typename T , typename A >
bool SafeNetSerializeTArray_WithNetSerialize ( FArchive Ar,
TArray< T, A > &  Array,
class UPackageMap PackageMap 
)

◆ SerializeFixedVector() [1/2]

template<int32 MaxValue, uint32 NumBits>
bool SerializeFixedVector ( FVector3d Vector,
FArchive Ar 
)

◆ SerializeFixedVector() [2/2]

template<int32 MaxValue, uint32 NumBits>
bool SerializeFixedVector ( FVector3f Vector,
FArchive Ar 
)

◆ SerializeOptionalValue()

template<typename ValueType >
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.

◆ SerializePackedVector() [1/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool SerializePackedVector ( FVector3d Value,
FArchive Ar 
)

◆ SerializePackedVector() [2/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool SerializePackedVector ( FVector3f Value,
FArchive Ar 
)

◆ WriteFixedCompressedFloat()

template<int32 MaxValue, uint32 NumBits, typename T UE_REQUIRES>
bool WriteFixedCompressedFloat ( const T  Value,
FArchive Ar 
)

◆ WritePackedVector() [1/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool WritePackedVector ( FVector3d  Vector,
FArchive Ar 
)

◆ WritePackedVector() [2/2]

template<int32 ScaleFactor, int32 MaxBitsPerComponent>
bool WritePackedVector ( FVector3f  Value,
FArchive Ar 
)