UActorChannel::ReplicateSubobject

Subobject Replication state

Windows
MacOS
Linux

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/Engine/ActorChannel.h

Include

#include "Engine/ActorChannel.h"

Source

/Engine/Source/Runtime/Engine/Private/DataChannel.cpp

Syntax

bool ReplicateSubobject
(
    UObject * Obj,
    FOutBunch & Bunch,
    const FReplicationFlags & RepFlags
)

Remarks

Subobject Replication state

Concepts: ObjID - this is an arbitrary identifier given to us by the game code. RepKey - this is an idenifier for the current replicated state.

ObjID should be constant per object or "category". Its up to the game code. For example the game code could use 0 to determine if an entire array is dirty, then usen 1-N for each subobject in that list. Or it could have 5 arrays using 0-4, and then use 100*ArrayNum + idx for the items in the array.

RepKey should change as the subobject changes. Each time a subobject is marked dirty, its RepKey should change.

GameCode should call ::KeyNeedsToReplicate(ObjID, RepKey) to determine if it needs to replicate. For example:

bool AMyActorClass::ReplicateSubobjects(UActorChannel *Channel, FOutBunch *Bunch, FReplicationFlags *RepFlags) { bool WroteSomething = false;

if (Channel->KeyNeedsToReplicate(0, ReplicatedArrayKey) ) // Does the array need to replicate? { for (int32 idx = 0; idx < ReplicatedSubobjects.Num(); ++idx ) { UMyActorSubobjClass *Obj = ReplicatedSubObjects[idx]; if (Channel->KeyNeedsToReplicate(1 + idx, Obj->RepKey)) { WroteSomething |= Channel->ReplicateSubobject(Obj, *Bunch, *RepFlags); } } }

return WroteSomething; }

void UMyActorSubobjClass::MarkDirtyForReplication() { this->RepKey++; MyOwningActor->ReplicatedArrayKey++; }

Replicates given subobject on this actor channel

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss