UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PropertyNetSerializerInfoRegistry.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
8#include "Templates/Casts.h"
9#include "Templates/Tuple.h"
10#include "UObject/NameTypes.h"
11#include "UObject/UnrealType.h"
12
13namespace UE::Net
14{
15
16class FFragmentRegistrationContext;
17class FReplicationFragment;
18struct FReplicationStateDescriptor;
20typedef FReplicationFragment* (*CreateAndRegisterReplicationFragmentFunc)(UObject*, const FReplicationStateDescriptor*, FFragmentRegistrationContext&);
21
22}
23
24namespace UE::Net
25{
26
35template<typename StructName>
36constexpr auto IsDeclaredType(StructName*) -> decltype(sizeof(StructName))
37{
38 return true;
39}
40
41constexpr auto IsDeclaredType(void*)
42{
43 return false;
44}
45
52{
53 virtual const FFieldClass* GetPropertyTypeClass() const { return nullptr; }
54 virtual bool IsSupported(const FProperty* Property) const { return true; }
55 virtual const FNetSerializer* GetNetSerializer(const FProperty* Property) const { return nullptr; }
56 virtual bool CanUseDefaultConfig(const FProperty* Property) const { return true; }
57 virtual const FNetSerializerConfig* BuildNetSerializerConfig(void* NetSerializerConfigBuffer, const FProperty* Property) const { return nullptr; }
60
62 {
63 return StructName == InStructName;
64 }
65
66protected:
67 // Used by named struct serializers.
69};
70
109
114// Helper to implement simple default PropertyNetSerializerInfo for primitive types
115template <typename T, typename ConfigType = FNetSerializerConfig>
125
126// Helper to implement simple default PropertyNetSerializerInfo for structs
156
158{
161
162 IRISCORE_API virtual const FFieldClass* GetPropertyTypeClass() const override;
163 IRISCORE_API virtual bool IsSupported(const FProperty* Property) const override;
164 IRISCORE_API virtual const FNetSerializer* GetNetSerializer(const FProperty* Property) const override final;
165 IRISCORE_API virtual bool CanUseDefaultConfig(const FProperty* Property) const override final;
167
168protected:
169 // Maximum size of quantized state in bits
171
172 // If set this class should not be included in the default state hash.
174};
175
193
194// Issue fatal error if matching trait found in UsedReplicationStateTraits is not set for the Serializer.
196
197}
198
199// Produce a compiler error if the name does not correspond to a declared UE type.
200#define UE_NET_IS_DECLARED_TYPE(Name) \
201 static_assert( \
202 UE::Net::IsDeclaredType((struct F##Name*)nullptr) || \
203 UE::Net::IsDeclaredType((struct U##Name*)nullptr) \
204 , "The UE type name '" #Name "' cannot be found. Make sure you have removed the 'F' or 'U' prefix from the type name.");
205
206// Only needed if we want to export PropertyNetSerializerInfo, this goes in the header if we need to export it
207#define UE_NET_DECLARE_NETSERIALIZER_INFO(NetSerializerInfo) \
208const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##NetSerializerInfo();
209
210// Implement FPropertyNetSerializerInfo from struct, this goes in the cpp file
211#define UE_NET_IMPLEMENT_NETSERIALIZER_INFO(NetSerializerInfo) \
212const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##NetSerializerInfo() { static NetSerializerInfo StaticInstance; return StaticInstance; };
213
214// Implement simple FPropertyNetSerializerInfo binding a SerializerType to the property
215#define UE_NET_IMPLEMENT_SIMPLE_NETSERIALIZER_INFO(PropertyType, SerializerName) \
216const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##PropertyType() { static UE::Net::TSimplePropertyNetSerializerInfo<PropertyType> StaticInstance(UE_NET_GET_SERIALIZER(SerializerName)); return StaticInstance; };
217
218// Implement simple FPropertyNetSerializerInfo for struct types with custom serializers
219#define UE_NET_IMPLEMENT_NAMED_STRUCT_NETSERIALIZER_INFO(Name, SerializerName) \
220const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##Name() { static UE::Net::FNamedStructPropertyNetSerializerInfo StaticInstance(Name, UE_NET_GET_SERIALIZER(SerializerName)); return StaticInstance; };
221
227#define UE_NET_IMPLEMENT_NAMED_STRUCT_NETSERIALIZER_WITH_CUSTOM_FRAGMENT_INFO(Name, SerializerName, CreateAndRegisterReplicationFragmentFunction) \
228const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##Name() \
229{ \
230 static UE::Net::FNamedStructPropertyNetSerializerInfo StaticInstance(Name, UE_NET_GET_SERIALIZER(SerializerName)); \
231 StaticInstance.SetCreateAndRegisterReplicationFragmentFunction(CreateAndRegisterReplicationFragmentFunction); \
232 return StaticInstance; \
233};
234
235// Implement FPropertyNetSerializerInfo for cases where LastResortPropertyNetSerializer is needed for struct with custom serialization.
236#define UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_INFO(StructName) \
237const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##StructName() { static UE::Net::FNamedStructLastResortPropertyNetSerializerInfo StaticInstance(StructName); return StaticInstance; };
238
239// Implement FPropertyNetSerializerInfo for cases where LastResortPropertyNetSerializer is needed for struct with custom serialization, with quantized state size override.
240#define UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_INFO_WITH_SIZE_OVERRIDE(StructName, MaxBits) \
241const UE::Net::FPropertyNetSerializerInfo& GetPropertyNetSerializerInfo_##StructName() { static UE::Net::FNamedStructLastResortPropertyNetSerializerInfo StaticInstance(StructName, MaxBits); return StaticInstance; };
242
243// Register
244#define UE_NET_REGISTER_NETSERIALIZER_INFO(Name) \
245UE::Net::FPropertyNetSerializerInfoRegistry::Register(&GetPropertyNetSerializerInfo_##Name());
246
247// Unregister
248#if !IS_MONOLITHIC
249#define UE_NET_UNREGISTER_NETSERIALIZER_INFO(Name) \
250UE::Net::FPropertyNetSerializerInfoRegistry::Unregister(&GetPropertyNetSerializerInfo_##Name());
251#else
252#define UE_NET_UNREGISTER_NETSERIALIZER_INFO(...)
253#endif
254
255// Implement minimal required delegates for a NetSerializer
256#define UE_NET_IMPLEMENT_NETSERIALIZER_REGISTRY_DELEGATES(Name) \
257struct F##Name##NetSerializerRegistryDelegates : protected UE::Net::FNetSerializerRegistryDelegates \
258{ \
259 ~F##Name##NetSerializerRegistryDelegates() { UE_NET_UNREGISTER_NETSERIALIZER_INFO(PropertyNetSerializerRegistry_NAME_##Name); } \
260 virtual void OnPreFreezeNetSerializerRegistry() override { UE_NET_REGISTER_NETSERIALIZER_INFO(PropertyNetSerializerRegistry_NAME_##Name); } \
261}; \
262static F##Name##NetSerializerRegistryDelegates Name##NetSerializerRegistryDelegates;
263
264// Utility that can be used to forward serialization of a Struct to a specific NetSerializer
265#define UE_NET_IMPLEMENT_FORWARDING_NETSERIALIZER_AND_REGISTRY_DELEGATES(Name, SerializerName) \
266 static const FName PropertyNetSerializerRegistry_NAME_##Name( PREPROCESSOR_TO_STRING(Name) ); \
267 UE_NET_IMPLEMENT_NAMED_STRUCT_NETSERIALIZER_INFO(PropertyNetSerializerRegistry_NAME_##Name, SerializerName); \
268 UE_NET_IMPLEMENT_NETSERIALIZER_REGISTRY_DELEGATES(Name)
269
270
271// Utility that can be used to forward serialization of a Struct to a last resort net serializer
272#define UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_AND_REGISTRY_DELEGATES(Name) \
273 UE_NET_IS_DECLARED_TYPE(Name); \
274 static const FName PropertyNetSerializerRegistry_NAME_##Name( PREPROCESSOR_TO_STRING(Name) ); \
275 UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_INFO(PropertyNetSerializerRegistry_NAME_##Name); \
276 UE_NET_IMPLEMENT_NETSERIALIZER_REGISTRY_DELEGATES(Name)
277
278// Utility that can be used to forward serialization of a Struct to a last resort net serializer with a maximum quantized size
279#define UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_AND_REGISTRY_DELEGATES_WITH_SIZE_OVERRIDE(Name, MaxBits) \
280 UE_NET_IS_DECLARED_TYPE(Name); \
281 static const FName PropertyNetSerializerRegistry_NAME_##Name( PREPROCESSOR_TO_STRING(Name) ); \
282 UE_NET_IMPLEMENT_NAMED_STRUCT_LASTRESORT_NETSERIALIZER_INFO_WITH_SIZE_OVERRIDE(PropertyNetSerializerRegistry_NAME_##Name, MaxBits); \
283 UE_NET_IMPLEMENT_NETSERIALIZER_REGISTRY_DELEGATES(Name)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Field.h:66
Definition NameTypes.h:617
Definition UnrealType.h:174
Definition UnrealType.h:6306
Definition Array.h:670
Definition PropertyNetSerializerInfoRegistry.h:75
static IRISCORE_API const FPropertyNetSerializerInfo * GetNopNetSerializerInfo()
Definition PropertyNetSerializerInfoRegistry.cpp:214
static IRISCORE_API void Unregister(const FPropertyNetSerializerInfo *Info)
Definition PropertyNetSerializerInfoRegistry.cpp:43
static IRISCORE_API void Freeze()
Definition PropertyNetSerializerInfoRegistry.cpp:55
static IRISCORE_API const FPropertyNetSerializerInfo * FindSerializerInfo(const FProperty *Property)
Definition PropertyNetSerializerInfoRegistry.cpp:142
static IRISCORE_API const FPropertyNetSerializerInfo * FindStructSerializerInfo(const FName Name)
Definition PropertyNetSerializerInfoRegistry.cpp:187
static IRISCORE_API void Reset()
Definition PropertyNetSerializerInfoRegistry.cpp:49
Definition Object.h:95
Definition NetworkVersion.cpp:28
void ValidateForwardingNetSerializerTraits(const FNetSerializer *Serializer, EReplicationStateTraits UsedReplicationStateTraits)
Definition PropertyNetSerializerInfoRegistry.cpp:219
FReplicationFragment *(* CreateAndRegisterReplicationFragmentFunc)(UObject *Owner, const FReplicationStateDescriptor *Descriptor, FFragmentRegistrationContext &Context)
Definition CoreNet.h:55
constexpr auto IsDeclaredType(StructName *) -> decltype(sizeof(StructName))
Definition PropertyNetSerializerInfoRegistry.h:36
EReplicationStateTraits
Definition ReplicationStateDescriptor.h:163
Definition NetSerializerConfig.h:17
Definition Tuple.h:652
Definition PropertyNetSerializerInfoRegistry.h:158
bool bExcludeFromDefaultStateHash
Definition PropertyNetSerializerInfoRegistry.h:173
virtual IRISCORE_API const FNetSerializer * GetNetSerializer(const FProperty *Property) const override final
Definition PropertyNetSerializerInfoRegistry.cpp:110
virtual IRISCORE_API FNetSerializerConfig * BuildNetSerializerConfig(void *NetSerializerConfigBuffer, const FProperty *Property) const override final
Definition PropertyNetSerializerInfoRegistry.cpp:120
virtual IRISCORE_API bool CanUseDefaultConfig(const FProperty *Property) const override final
Definition PropertyNetSerializerInfoRegistry.cpp:115
virtual IRISCORE_API bool IsSupported(const FProperty *Property) const override
Definition PropertyNetSerializerInfoRegistry.cpp:105
virtual IRISCORE_API const FFieldClass * GetPropertyTypeClass() const override
Definition PropertyNetSerializerInfoRegistry.cpp:100
uint32 MaxQuantizedSizeBits
Definition PropertyNetSerializerInfoRegistry.h:170
IRISCORE_API FLastResortPropertyNetSerializerInfo()
Definition PropertyNetSerializerInfoRegistry.cpp:88
Definition PropertyNetSerializerInfoRegistry.h:177
FNamedStructLastResortPropertyNetSerializerInfo(const FName InPropertyFName, const uint32 InMaxBits)
Definition PropertyNetSerializerInfoRegistry.h:184
FNamedStructLastResortPropertyNetSerializerInfo(const FName InPropertyFName)
Definition PropertyNetSerializerInfoRegistry.h:178
virtual IRISCORE_API const FFieldClass * GetPropertyTypeClass() const override
Definition PropertyNetSerializerInfoRegistry.cpp:131
virtual IRISCORE_API bool IsSupported(const FProperty *Property) const override
Definition PropertyNetSerializerInfoRegistry.cpp:136
Definition PropertyNetSerializerInfoRegistry.h:128
FNamedStructPropertyNetSerializerInfo(const FName InPropertyFName, const FNetSerializer &InSerializer)
Definition PropertyNetSerializerInfoRegistry.h:131
TSimplePropertyNetSerializerInfo< FStructProperty > Super
Definition PropertyNetSerializerInfoRegistry.h:129
virtual bool IsSupported(const FProperty *Property) const override
Definition PropertyNetSerializerInfoRegistry.h:137
void SetCreateAndRegisterReplicationFragmentFunction(CreateAndRegisterReplicationFragmentFunc InCreateAndRegisterReplicationFragmentFunction)
Definition PropertyNetSerializerInfoRegistry.h:148
virtual CreateAndRegisterReplicationFragmentFunc GetCreateAndRegisterReplicationFragmentFunction() const
Definition PropertyNetSerializerInfoRegistry.h:143
Definition NetSerializer.h:377
Definition PropertyNetSerializerInfoRegistry.h:52
virtual const FNetSerializer * GetNetSerializer(const FProperty *Property) const
Definition PropertyNetSerializerInfoRegistry.h:55
virtual const FFieldClass * GetPropertyTypeClass() const
Definition PropertyNetSerializerInfoRegistry.h:53
virtual bool IsSupported(const FProperty *Property) const
Definition PropertyNetSerializerInfoRegistry.h:54
virtual bool CanUseDefaultConfig(const FProperty *Property) const
Definition PropertyNetSerializerInfoRegistry.h:56
bool IsSupportedStruct(FName InStructName) const
Definition PropertyNetSerializerInfoRegistry.h:61
virtual const FNetSerializerConfig * BuildNetSerializerConfig(void *NetSerializerConfigBuffer, const FProperty *Property) const
Definition PropertyNetSerializerInfoRegistry.h:57
FName StructName
Definition PropertyNetSerializerInfoRegistry.h:68
virtual CreateAndRegisterReplicationFragmentFunc GetCreateAndRegisterReplicationFragmentFunction() const
Definition PropertyNetSerializerInfoRegistry.h:59
Definition PropertyNetSerializerInfoRegistry.h:117
const FNetSerializer & Serializer
Definition PropertyNetSerializerInfoRegistry.h:118
virtual const FFieldClass * GetPropertyTypeClass() const override
Definition PropertyNetSerializerInfoRegistry.h:121
virtual FNetSerializerConfig * BuildNetSerializerConfig(void *NetSerializerConfigBuffer, const FProperty *Property) const override
Definition PropertyNetSerializerInfoRegistry.h:123
TSimplePropertyNetSerializerInfo(const FNetSerializer &InSerializer)
Definition PropertyNetSerializerInfoRegistry.h:120
virtual const FNetSerializer * GetNetSerializer(const FProperty *Property) const override
Definition PropertyNetSerializerInfoRegistry.h:122