UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypedReplicationFragment.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7namespace UE::Net
8{
9
10/*
11* Typed replication fragments are used when we have generated ReplicationStates
12* and will call the SetReplicatedState method on the parent class
13* $IRIS TODO: Introduce policies based on ReplicationStateTraits, i.e. should we call other functions on Init etc?
14*/
15template <typename T, typename ReplicationStateT>
17{
18public:
19 // Receive only
21
22 // Replicate
23 TReplicationFragment(T& OwnerIn, ReplicationStateT& SrcReplicationState) : FReplicationFragment(EReplicationFragmentTraits::CanReplicate), Owner(OwnerIn), SrcState(&SrcReplicationState) {}
24
26
27protected:
28 // FReplicationFragment
30
31
32private:
33 T& Owner;
34 ReplicationStateT* SrcState;
35};
36
37template <typename T, typename ReplicationStateT>
39{
40 // Cast to the expected type
41 const ReplicationStateT* ReplicationState = reinterpret_cast<const ReplicationStateT*>(Context.StateBufferData.ExternalStateBuffer);
42
43 // $TODO: We need a state management system here so that we can keep states around until update time
44 // either we implement this at this level or we make this part of the replication system, maybe a linear allocator during receive that we will free after we have applied the states
45 Owner.ApplyReplicationState(*ReplicationState, Context);
46}
47
48template <typename T, typename ReplicationStateT>
50{
51 Context.RegisterReplicationFragment(this, ReplicationStateT::GetReplicationStateDescriptor(), SrcState);
52}
53
54}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition ReplicationFragment.h:244
Definition ReplicationFragment.h:176
Definition TypedReplicationFragment.h:17
TReplicationFragment(T &OwnerIn)
Definition TypedReplicationFragment.h:20
void Register(FFragmentRegistrationContext &Context)
Definition TypedReplicationFragment.h:49
virtual void ApplyReplicatedState(FReplicationStateApplyContext &Context) const override
Definition TypedReplicationFragment.h:38
TReplicationFragment(T &OwnerIn, ReplicationStateT &SrcReplicationState)
Definition TypedReplicationFragment.h:23
Definition NetworkVersion.cpp:28
EReplicationFragmentTraits
Definition ReplicationFragment.h:102
Definition ReplicationFragment.h:66