ue-networking-replication

Use this skill when working on multiplayer networking, replication, RPC calls, net role logic, server/client authority, prediction, or synchronizing game state. Also use when the user mentions 'DOREPLIFETIME', 'dedicated server', 'replicated', or 'net role'. See references/replication-patterns.md fo

By quodsoler · 822 installs

npx skills add quodsoler/unreal-engine-skills --skill ue-networking-replication

Source repository · Upstream listing

UE Networking & Replication You are an expert in Unreal Engine's networking and replication systems. Context Check Read .agents/ue project context.md for this project's multiplayer configuration. Look for: server topology (dedicated, listen, P2P), player count, replicated classes, and any custom net drivers. If the context file is absent, ask: 1. Server topology? (dedicated, listen, P2P) 2. Maximum player count per session? 3. Which actors or components need to replicate data? 4. Are you using Gameplay Ability System (GAS)? Net Roles and Authority UE uses a server authoritative model: the server is the source of truth for game state. Clients predict locally and reconcile with server corrections. Every actor on every machine has a local role and a remote role ( ENetRole ). From Actor.h : Net modes: NM Standalone , NM DedicatedServer , NM ListenServer , NM Client . Role matrix for a replicated Pawn: Machine GetLocalRole() GetRemoteRole() Server ROLE Authority ROLE AutonomousProxy or SimulatedProxy Owning Client ROLE AutonomousProxy ROLE Authority Other Clients ROLE SimulatedProxy ROLE Authority Listen server caveat: the host is both ROLE Authority and locally controlled. Use IsLocallyControlled() to distinguish logic that should skip the host player. UNetDriver UNetDriver is the core transport class responsible for managing all network connections and packet delivery for a world. It owns the list of UNetConnection objects and drives the replication tick. Access it via UWorld::GetNetDriver() . For most gameplay code you never interact with UNetDriver directly; it is relevant when writing custom net drivers, profiling connection state, or debugging packet loss. Property Replication Actor Setup From Actor.h : SetReplicates , SetReplicateMovement , SetNetUpdateFrequency , SetMinNetUpdateFrequency , and SetNetCullDistanceSquared are all ENGINE API . FRepMovement: when bReplicateMovement = true , the engine serializes position, velocity, and rotation into an FRepMovement struct (declared in Actor.h ) and sends it to simulated proxies. UCharacterMovementComponent bypasses this with its own prediction based replication; it writes compressed moves via FSavedMove Character and reconciles them server side, so SetReplicateMovement(false) is the correct default for characters using CMC. Declaring Properties GetLifetimeReplicatedProps Conditions: COND None (all), COND OwnerOnly , COND SkipOwner , COND SimulatedOnly , COND AutonomousOnly , COND InitialOnly , COND Custom . Use COND OwnerOnly for private player data (inventory, currency). Use COND InitialOnly for immutable spawn data (team, character class). Initial replication burst : When a client first joins or an actor first becomes relevant, ALL replicated properties send at once regardless of conditions ( COND InitialOnly fires exactly once here). This burst can saturate the actor channel — keep initial state compact and use COND InitialOnly for spawn time only data to reduce ongoing bandwidth. FRepLayout (Internal) FRepLayout is an internal engine struct that describes which properties of a class are replicated and how. It handles delta compression (only changed properties are sent) and evaluates DOREPLIFETIME CONDITION filters per connection. Developers rarely interact with FRepLayout directly, but knowing it exists helps when debugging why a property is or is not replicating: the layout is built once per class and cached, so dynamic changes to conditions require DOREPLIFETIME WITH PARAMS FAST or bIsPushBased patterns rather than modifying the struct at runtime. Large Arrays: FFastArraySerializer Plain TArray sends the full array on any change. Use FFastArraySerializer for delta only replication. See references/replication patterns.md Pattern 3 for a complete inventory implementation. Custom Struct Serialization Implement NetSerialize on a USTRUCT and add TStructOpsTypeTraits with WithNetSerializer = true to control binary layout manually. Use FVector NetQuantize10 (0.1 cm precision) instead of raw FVector to halve position bandwidth. Remote Procedure Calls (RPCs) See references/rpc decision guide.md for the full decision flowchart. Implementations always end in Implementation . Server RPCs with validation also need Validate (return false to kick the client). Reliable — guaranteed delivery; use for state changing actions (purchase, spawn, possession). Unreliable — fire and forget; use for high frequency cosmetics. Real examples from PlayerController.h : RPC ownership: Server RPCs must be called on an actor whose ownership chain leads to the calling client's APlayerController . Client RPCs must be called on an actor owned by a player with a NetConnection . Calls on unowned actors are silently dropped. RPC Parameter Rules : Only net addressable types are valid — basic types ( int32 , float , FString , FVector ), replicated UObject pointers (arrive as nullptr if not replicated), and USTRUCT(BlueprintType) structs. Non replicated UObject pointers arrive as nullptr ; pass an ID and look the object up on the remote side. Large payloads ( 1 KB) should use replicated properties instead of RPC parameters. TArray and TMap parameters are supported but watch for bandwidth impact. Ownership and Relevancy Default relevancy culls actors beyond NetCullDistanceSquared from the client viewpoint. NetPriority determines which actors win when bandwidth is saturated. Dormancy: actors that rarely change can pause replication entirely. Re relevancy : When an actor moves outside NetCullDistanceSquared it stops replicating. When it returns to range, the engine treats it as a fresh relevancy event — sending another initial burst and firing all OnRep callbacks with current server state. Design OnRep functions to be idempotent (tolerate being called multiple times with the same value). Dormant actors ( DORM DormantAll ) behave similarly when woken — they flush all dirty properties at once. Subobject Replication Modern API (UE 5.1+) From Actor.h : Enable with bReplicateUsingRegisteredSubObjectList = true (now the default). Call AddReplicatedSubObject on the server during BeginPlay ; call RemoveReplicatedSubObject in EndPlay . Legacy API Override ReplicateSubobjects when bReplicateUsingRegisteredSubObjectList = false : Client Side Prediction Pattern (for non movement systems without GAS): When the server rejects a prediction, smooth the visual correction to avoid jarring snaps: interpolate the actor to the corrected position over 2 3 frames rather than teleporting. UCharacterMovementComponent handles this automatically via NetworkSmoothingMode ( Linear , Exponential , or Disabled ). CharacterMovementComponent has full built in prediction. Extend FSavedMove Character and override PhysCustom to support custom movement modes. Prediction eligibility : Only UCharacterMovementComponent and GAS ( UAbilitySystemComponent with FPredictionKey ) have engine managed prediction and rollback. Raw UPROPERTY(Replicated) properties have no built in prediction — if you write them locally before the server confirms, the server's replicated value overwrites the client value with no rollback. For non CMC/GAS state, use local only variables for visual prediction and apply the authoritative value in OnRep . GAS and FPredictionKey: GAS uses FPredictionKey to link client predicted actions with server confirmations. The key is generated on the client (via FPredictionKey::CreateNewPredictionKey ), embedded in the Server RPC, and matched on the server when applying GameplayEffect s or activating abilities. If the server determines the prediction was invalid, every GameplayEffect and attribute change tagged with that key is automatically rolled back on the client. You do not construct FPredictionKey manually in most cases; UAbilitySystemComponent::TryActivateAbility manages the lifecycle. Relevant when writing custom UGameplayAbility subclasses that need scoped prediction windows ( FScopedPredictionWindow ). See ue gameplay abilities for the full GAS networking details. Actor Replication Setup Checklist Replication Graph For large player counts (50+ connections), the default net driver relevancy checks become expensive. UReplicationGraph replaces per connection per actor relevancy with spatial and policy based nodes. Key node types: UReplicationGraphNode GridSpatialization2D (spatial), UReplicationGraphNode AlwaysRelevant (GameState, managers), UReplicationGraphNode AlwaysRelevant ForConnection (PlayerController, PlayerState, HUD), UReplicationGraphNode ActorList (custom lists). Common Mistakes Mistake Fix Modifying state without HasAuthority() guard Add if (!HasAuthority()) return; Server RPC without WithValidation — client sends arbitrary values Add WithValidation ; validate in Validate Calling Client / NetMulticast from the client — silently dropped Only call from server; guard with HasAuthority() Plain TArray on replicated component — full array sent on every change Use FFastArraySerializer Omitting Super::GetLifetimeReplicatedProps — parent properties silently dropped Always call Super first Passing non replicated UObject in RPC params — arrives as nullptr Pass an ID; look up object on remote side Using NetMulticast for persistent state — late joining clients miss it Use UPROPERTY(Replicated) for state Replicating cosmetic only properties — increases bandwidth for data clients can compute locally Only replicate gameplay critical state; derive visuals client side APlayerController Replication Scope APlayerController exists only on the server and the owning client — not on other clients. Put data meant for all clients on APawn or APlayerState . From PlayerController.h : UNetConnection represents a single client's network connection on the server. Each connected client has exactly one UNetConnection owned by UNetDriver . Retrieve it with APlayerController::GetNetConnection() . It is used for: Ownership checks: an actor's owning connection determines which client RPCs it can receive and which COND OwnerOnly properties it sees. RPC routing: Server RPCs are only accepted from the actor's owning connection. Detecting disconnects: bind to AGameModeBase::OnLogout or check NetConnection GetConnectionState() == USOCK Closed (or IsClosingOrClosed() ) rather than polling NetConnection directly. Use APlayerController for connection scoped Client RPCs (HUD updates, voice, level streaming notifications). Use APawn or APlayerState for world visible state. Related Skills ue gameplay framework — AGameMode (server only), AGameState / APlayerState (replicated to all), APawn net roles ue gameplay abilities — GAS prediction keys, attribute set replication, GameplayEffect replication ue cpp foundations — UPROPERTY/UFUNCTION macros, module includes Reference Files references/replication patterns.md — health, inventory (FFastArraySerializer), ability state, team data, subobject, dormancy, and custom relevancy patterns references/rpc decision guide.md — Server/Client/NetMulticast decision flowchart, Reliable vs Unreliable rules, ownership routing, and common RPC mistakes