Replication¶
Properties (state) and actors (entities) are kept in sync from server to clients automatically when configured correctly.
Actor replication¶
AMyActor::AMyActor()
{
bReplicates = true;
bReplicateMovement = true;
NetUpdateFrequency = 30.f;
MinNetUpdateFrequency = 5.f;
}
The server decides which clients see the actor (relevancy).
Property replication¶
UPROPERTY(ReplicatedUsing=OnRep_Health)
float Health = 100.f;
UFUNCTION()
void OnRep_Health(float OldHealth);
void AMyActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Out) const
{
Super::GetLifetimeReplicatedProps(Out);
DOREPLIFETIME(AMyActor, Health);
DOREPLIFETIME_CONDITION(AMyActor, Ammo, COND_OwnerOnly);
}
ReplicatedUsingcallsOnRep_<Name>on clients whenever the value changes.COND_OwnerOnly/COND_SkipOwnerfilter who receives the update.COND_Customlets you toggle replication dynamically.
Push Model¶
Default replication checks each property each tick. Push Model flips it: properties only replicate when explicitly marked dirty.
Enable in Project Settings → Networking → Use Network Push Model. Order-of-magnitude reduction in CPU for high-actor-count games.
Subobject replication¶
Replicate components on a replicated actor: set bReplicates = true on the component. For arrays of subobjects:
void AMyActor::PreReplication(IRepChangedPropertyTracker& Changer)
{
Super::PreReplication(Changer);
for (UMyComp* C : Components) AddReplicatedSubObject(C);
}
Network role¶
| Role | Where |
|---|---|
ROLE_Authority |
The server's instance of the actor |
ROLE_AutonomousProxy |
The local owner's replicated copy (e.g. own pawn) |
ROLE_SimulatedProxy |
A replicated copy of an actor owned by someone else |
Most authority checks: if (HasAuthority()) { ... }.
Tick groups + replication order¶
Replication happens in TG_LastDemotable. Avoid setting replicated state in client BeginPlay — set it server-side; the client will receive via OnRep.
Common pitfalls¶
- Forgetting
DOREPLIFETIMEafter declaring aReplicatedproperty. - Calling RPCs on actors that haven't replicated yet (early in spawn).
- Assuming
BeginPlayorder is consistent across server/client — order can differ. - Replicating large structs every frame — use Push Model or split into smaller properties.