APawn::PreReplication
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualoverride
Description
Called by the replication system on the server just before each actor is replicated to clients. APawn uses it to pack the RemoteViewPitch into the replicated byte, and to conditionally enable replication of certain properties.
Caveats & Gotchas
- • Always call Super::PreReplication(ChangedPropertyTracker) — APawn's implementation packs RemoteViewPitch16 and calls the parent AActor logic. Skipping it corrupts remote pitch replication.
- • This is called every replication frame for every relevant connection; keep any logic here extremely cheap. Heavy work (collision queries, asset loads) belongs in Tick, not PreReplication.
- • DOREPLIFETIME_ACTIVE_OVERRIDE macros must be called from this function (not GetLifetimeReplicatedProps) when you want to dynamically enable or disable a property's replication based on runtime state.
Signature
virtual void PreReplication( IRepChangedPropertyTracker & ChangedPropertyTracker ) override Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ChangedPropertyTracker | IRepChangedPropertyTracker& | Tracks which replicated properties have changed and need to be sent this frame. | — |
Return Type
void Example
Conditionally replicate a property only when alive C++
void AMyPawn::PreReplication(IRepChangedPropertyTracker& ChangedPropertyTracker)
{
Super::PreReplication(ChangedPropertyTracker);
// Only replicate shield value while the pawn is alive
DOREPLIFETIME_ACTIVE_OVERRIDE(AMyPawn, ShieldValue, !bIsDead);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?