中EN

Replicate Actor Properties

  • Server sends an update to each client whenever a replicated property changes.
  • Replicated vs ReplicatedUsing (RepNotify OnRep_ called on clients). NotReplicated for members within a replicated struct.
  • Steps: UPROPERTY(Replicated); bReplicates = true; override GetLifetimeReplicatedProps and DOREPLIFETIME(ADerivedActor, Health); include Net/UnrealNetwork.h.
  • RepNotify may take a parameter of the same type (value or const ref) receiving the previous value.
  • Blueprint: Set node on a replicated property automatically calls RepNotify; macros/functions taking by reference generally don't. (C++ differs.)
  • Once registered, cannot unregister; replicated for the lifetime of the object; system shares work across connections. By default replicates only when changed.
  • DOREPLIFETIME_CONDITION (e.g. COND_OwnerOnly); DOREPLIFETIME_CONDITION_NOTIFY with REPNOTIFY_Always / REPNOTIFY_OnChanged; DOREPLIFETIME_WITH_PARAMS (FDoRepLifetimeParams) — more control, more overhead.
  • Conditions: COND_None, COND_InitialOnly, COND_OwnerOnly, COND_SkipOwner, COND_SimulatedOnly, COND_AutonomousOnly, COND_SimulatedOrPhysics, COND_InitialOrOwner, COND_Custom, COND_ReplayOrOwner, COND_ReplayOnly, COND_SimulatedOnlyNoReplay, COND_SimulatedOrPhysicsNoReplay, COND_SkipReplay, COND_Dynamic, COND_Never.
  • COND_Custom + DOREPLIFETIME_ACTIVE_OVERRIDE in PreReplication; per actor, not per connection (not safe to use per-connection state). Custom conditions cost more and cannot change per connection. _FAST variants build descriptor at compile time (no arrays except _STATIC_ARRAY).
  • Object references replicated as FNetworkGUID assigned by server. Supported: replicated actors, stably-named non-replicated actors, replicated components, stably-named components, non-actor non-component UObjects from loaded packages. IsSupportedForNetworking. Stably named: loaded from packages, not spawned; components loaded from package, added by simple construction scripts, or SetNetAddressable (e.g. components added in C++ constructor).

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原