UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ReplicationFragment.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6
7#include "Containers/Array.h"
8#include "Containers/Map.h"
9
11#include "Misc/EnumClassFlags.h"
12
13// Forward declarations
14
16namespace UE::Net
17{
18 class FFragmentRegistrationContext;
19 class FNetSerializationContext;
20 struct FReplicationStateDescriptor;
21 namespace Private
22 {
23 class FReplicationStateDescriptorRegistry;
24 struct FFragmentRegistrationContextPrivateAccessor;
25 }
26}
27
28namespace UE::Net
29{
30
32{
33public:
35 : Owners(InOwners)
36 , OwnerCount(0)
37 , MaxOwnerCount(InMaxOwnerCount)
38 {
39 }
40
41 void AddOwner(UObject* Object)
42 {
43 if (OwnerCount < MaxOwnerCount)
44 {
45 if (OwnerCount && Owners[OwnerCount - 1] == Object)
46 {
47 return;
48 }
49 Owners[OwnerCount] = Object;
50 ++OwnerCount;
51 }
52 }
53
54 UObject** GetOwners() const { return Owners; }
55 uint32 GetOwnerCount() const { return OwnerCount; }
56
57 void Reset() { OwnerCount = 0; }
58
59private:
60 UObject** Owners;
61 uint32 OwnerCount;
62 const uint32 MaxOwnerCount;
63};
64
66{
69
70 // We have two different variants of applying state data
71 // Either we let the ReplicationSystem create and construct a temporary state OR it is up to the ReplicationFragment to manage the external buffer
72 // We might for example want to allow a fragment to keep a persistent buffer and simply write directly into it.
74 {
76 struct
77 {
80 };
81 };
82
84
85 // Indicates that this is the first time we receive this state, (it might also be set if we get this call after resolving references)
87 // Set when we are applying state data and a member of the state contains an unresolvable object reference
89 // Set if this fragment is for a init state and the object has unresolved init references
91};
92
94{
95 None = 0U,
97};
99
102{
103 None = 0,
104
105 // Not implemented
107
108 // Fragment has rep notifies
110
111 // Save previous state before apply
113
114 // Fragment is owned by instance protocol and will be destroyed when the instance protocol is destroyed
116
117 // Pass raw quantized data when applying state data
119
120 // Fragment can be used to source replication data
122
123 // Fragment can receive replication data
125
126 // Fragment requires polling to detect dirtiness
127 NeedsPoll = CanReceive << 1,
128
129 // Fragment requires legacy callbacks
131
132 // Fragment requires PreSendUpdate to be called
134
135 // Fragment supports push based dirtiness
137
138 // Fragment supports full push based dirtiness
140
141 // Fragment is a PropertyReplication, or is using PropertyReplicationState
143
144 // Fragment has object references
146
147 // Fragment supports partial dequantized state in apply
149};
151
169
218
220{
221 None = 0U,
222
223 // Indicates that we only should register RPC:s
224 RegisterRPCsOnly = 1U,
225 // Indicates that this objects should use the CDO for class defaults instead of the archetype
227 // Allow building descriptors for FastArrays that contain additional properties, NOTE: This should be avoided as fastarrays normally only should contain a single replicated property.
229};
231
242
244{
245public:
253
255 const EReplicationFragmentTraits GetFragmentTraits() const { return FragmentTraits; }
256
258 void RegisterReplicationFragment(FReplicationFragment* Fragment, const FReplicationStateDescriptor* Descriptor, void* SrcReplicationStateBuffer)
259 {
260 Fragments.Add({ Descriptor, SrcReplicationStateBuffer, Fragment });
261 }
262
264 void SetIsFragmentlessNetObject(bool bIsFragmentless) { bIsAFragmentlessNetObject = bIsFragmentless; }
265
267 bool IsFragmentlessNetObject() const { return bIsAFragmentlessNetObject; }
268
270 bool WasRegistered() const
271 {
272 return Fragments.Num() > 0 || bIsAFragmentlessNetObject;
273 }
274
276 int32 NumFragments() const { return Fragments.Num(); }
277
279
280private:
281
282 FReplicationFragments Fragments;
283 Private::FReplicationStateDescriptorRegistry* ReplicationStateRegistry;
284 UReplicationSystem* ReplicationSystem;
285
287 UObject* MainObjectInstance = nullptr;
288
290 const UObject* Template = nullptr;
291
293 const UObject* MainObjectDefaultStateSource = nullptr;
294
295 const EReplicationFragmentTraits FragmentTraits;
296
297 bool bIsAFragmentlessNetObject = false;
298
299};
300
301}
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition ReplicationFragment.h:244
FFragmentRegistrationContext(Private::FReplicationStateDescriptorRegistry *InReplicationStateRegistry, UReplicationSystem *InReplicationSystem, const EReplicationFragmentTraits InFragmentTraits, UObject *MainObject)
Definition ReplicationFragment.h:246
void RegisterReplicationFragment(FReplicationFragment *Fragment, const FReplicationStateDescriptor *Descriptor, void *SrcReplicationStateBuffer)
Definition ReplicationFragment.h:258
void SetIsFragmentlessNetObject(bool bIsFragmentless)
Definition ReplicationFragment.h:264
bool WasRegistered() const
Definition ReplicationFragment.h:270
int32 NumFragments() const
Definition ReplicationFragment.h:276
const EReplicationFragmentTraits GetFragmentTraits() const
Definition ReplicationFragment.h:255
bool IsFragmentlessNetObject() const
Definition ReplicationFragment.h:267
Definition NetSerializationContext.h:31
Definition ReplicationFragment.h:176
virtual bool PollReplicatedState(EReplicationFragmentPollFlags PollOption=EReplicationFragmentPollFlags::PollAllState)
Definition ReplicationFragment.h:208
virtual void ReplicatedStateToString(FStringBuilderBase &StringBuilder, FReplicationStateApplyContext &Context, EReplicationStateToStringFlags Flags=EReplicationStateToStringFlags::None) const
Definition ReplicationFragment.h:213
FReplicationFragment & operator=(const FReplicationFragment &)=delete
EReplicationFragmentTraits Traits
Definition ReplicationFragment.h:216
FReplicationFragment(const FReplicationFragment &)=delete
virtual void ApplyReplicatedState(FReplicationStateApplyContext &Context) const =0
FReplicationFragment(EReplicationFragmentTraits InTraits)
Definition ReplicationFragment.h:181
virtual void CallRepNotifies(FReplicationStateApplyContext &Context)
Definition ReplicationFragment.h:202
virtual void CollectOwner(FReplicationStateOwnerCollector *Owners) const
Definition ReplicationFragment.h:197
virtual ~FReplicationFragment()
Definition ReplicationFragment.h:182
EReplicationFragmentTraits GetTraits() const
Definition ReplicationFragment.h:185
Definition ReplicationFragment.h:32
void AddOwner(UObject *Object)
Definition ReplicationFragment.h:41
FReplicationStateOwnerCollector(UObject **InOwners, uint32 InMaxOwnerCount)
Definition ReplicationFragment.h:34
void Reset()
Definition ReplicationFragment.h:57
UObject ** GetOwners() const
Definition ReplicationFragment.h:54
uint32 GetOwnerCount() const
Definition ReplicationFragment.h:55
Definition ReplicationStateDescriptorRegistry.h:31
Definition Object.h:95
Definition ReplicationSystem.h:70
Definition OverriddenPropertySet.cpp:45
@ None
Definition ReplicationDataStreamDebug.h:25
Definition NetworkVersion.cpp:28
EReplicationStateToStringFlags
Definition ReplicationFragment.h:94
EReplicationFragmentPollFlags
Definition ReplicationFragment.h:153
EReplicationFragmentTraits
Definition ReplicationFragment.h:102
TArray< FReplicationFragmentInfo, TInlineAllocator< 32 > > FReplicationFragments
Definition ReplicationFragment.h:241
EFragmentRegistrationFlags
Definition ReplicationFragment.h:220
Definition ReplicationFragment.h:236
const FReplicationStateDescriptor * Descriptor
Definition ReplicationFragment.h:237
void * SrcReplicationStateBuffer
Definition ReplicationFragment.h:238
FReplicationFragment * Fragment
Definition ReplicationFragment.h:239
Definition ReplicationFragment.h:66
FNetSerializationContext * NetSerializationContext
Definition ReplicationFragment.h:68
FStateBufferData StateBufferData
Definition ReplicationFragment.h:83
uint32 bIsInit
Definition ReplicationFragment.h:86
const FReplicationStateDescriptor * Descriptor
Definition ReplicationFragment.h:67
uint32 bMightHaveUnresolvableInitReferences
Definition ReplicationFragment.h:90
uint32 bHasUnresolvableReferences
Definition ReplicationFragment.h:88
Definition ReplicationStateDescriptor.h:199
Definition ReplicationFragmentInternal.h:10
const uint8 * RawStateBuffer
Definition ReplicationFragment.h:79
const uint32 * ChangeMaskData
Definition ReplicationFragment.h:78
uint8 * ExternalStateBuffer
Definition ReplicationFragment.h:75