TExcelTAD
Home › Multiplayer Game Networking › Unreal Replication

Unreal Replication

Unreal Engine has had a networking layer since its first version, and it shows: the gameplay framework is a client-server design. The server owns the authoritative copy of every replicated actor, clients get copies, and replication sends changed properties from server to clients while RPCs carry calls in either direction. Learn these five pieces and most Unreal multiplayer code reads easily: bReplicates, replicated properties, GetLifetimeReplicatedProps, RPC specifiers and network roles. The engine itself is covered in the Unreal course.

Who runs what

Unreal games run as one of these net modes: standalone, dedicated server (no local player), listen server (a player's game also acts as server) or client. The gameplay framework splits classes along that line:

Class Exists on Job
AGameMode server only rules: spawning, scoring, win conditions
AGameState server + all clients replicated match state (time left, team scores)
APlayerController server + the owning client one player's input and UI link
APlayerState server + all clients replicated per-player info (name, score, ping)
APawn / ACharacter server + clients that find it relevant the body in the world

Because AGameMode doesn't exist on clients, client code that calls GetWorld()->GetAuthGameMode() gets nullptr. That is a feature: rules live where cheaters can't touch them.

Replicated properties

An actor replicates when bReplicates is true. Each property you want sent is tagged in its header and registered in GetLifetimeReplicatedProps:

cpp
// ArenaCharacter.h
UCLASS()
class AArenaCharacter : public ACharacter
{
    GENERATED_BODY()
public:
    AArenaCharacter();
    virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

    UPROPERTY(ReplicatedUsing = OnRep_Health)
    int32 Health = 100;

    UPROPERTY(Replicated)
    int32 Ammo = 30;

    UFUNCTION()
    void OnRep_Health(int32 OldHealth);       // RepNotify; may take the previous value

    UFUNCTION(Server, Reliable)
    void ServerFire(FVector_NetQuantize AimPoint);

    UFUNCTION(NetMulticast, Unreliable)
    void MulticastMuzzleFlash();
};
cpp
// ArenaCharacter.cpp
#include "ArenaCharacter.h"
#include "Net/UnrealNetwork.h"

AArenaCharacter::AArenaCharacter()
{
    bReplicates = true;                        // ACharacter already does this; shown for clarity
}

void AArenaCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);
    DOREPLIFETIME(AArenaCharacter, Health);                       // to everyone
    DOREPLIFETIME_CONDITION(AArenaCharacter, Ammo, COND_OwnerOnly); // only the owning player sees ammo
}

void AArenaCharacter::OnRep_Health(int32 OldHealth)
{
    if (Health < OldHealth) { /* play hit reaction, update the HUD */ }
}

void AArenaCharacter::ServerFire_Implementation(FVector_NetQuantize AimPoint)
{
    if (Ammo <= 0) return;                     // server-side rules
    --Ammo;
    // ... trace from the muzzle, apply damage on the server ...
    MulticastMuzzleFlash();
}

void AArenaCharacter::MulticastMuzzleFlash_Implementation()
{
    // cosmetic: runs on the server and on every client the actor is relevant for
}

Rules that trip people up:

  • Replication is server → client only. Setting Health on a client changes only that client's copy, and the next update overwrites it.
  • Only changes are sent, at the actor's net update frequency, and only to connections for which the actor is relevant (close enough, owned, or always relevant). Several changes between two updates arrive as one.
  • Conditions filter receivers: COND_OwnerOnly, COND_SkipOwner, COND_InitialOnly, COND_SimulatedOnly, COND_AutonomousOnly and more.
  • RepNotify runs on clients when a new value arrives. In C++ the server does not call OnRep_ for its own writes; if the listen-server player needs the same effect, call the function yourself after setting the value.

RPCs

Specifier Called on Runs on
Server the owning client the server
Client the server the owning client
NetMulticast the server the server and all clients the actor is relevant for
  • RPCs are unreliable by default. Add Reliable for things that must arrive (a purchase, a round result), keep Unreliable for frequent cosmetic events. Reliable RPCs spammed every tick can stall a connection.
  • You write the body in Name_Implementation. Adding WithValidation also requires bool Name_Validate(...); returning false disconnects the caller, so keep it for impossible inputs, not for normal game rules.
  • A client can call a Server RPC only on an actor its connection owns (its PlayerController, its Pawn, things whose owner chain leads to them). Calls on other actors are dropped. That is the most common "my RPC never arrives" bug.

Roles and authority

Every actor copy knows its local role:

GetLocalRole() Meaning
ROLE_Authority this copy is authoritative (on the server)
ROLE_AutonomousProxy the owning client's copy of its own pawn: it predicts locally
ROLE_SimulatedProxy everyone else's copy: it only follows replicated state, smoothed

HasAuthority() is the short form of "am I the authority for this actor". Typical code branches on it:

cpp
void AArenaCharacter::TryFire(FVector AimPoint)
{
    if (HasAuthority()) { ServerFire_Implementation(AimPoint); }   // listen server or AI
    else                { PlayLocalFireEffects(); ServerFire(AimPoint); }  // predict cosmetics, ask the server
}

UCharacterMovementComponent already implements client prediction and server reconciliation for character movement (it saves moves, sends them, and replays them after a correction), which is why a default third-person template feels responsive online. Your own abilities need the same care; the Gameplay Ability System adds prediction keys for that.

Note: Epic also ships Iris, a newer replication system. It is opt-in and works alongside the default system, and its status changes between engine versions, so check the documentation for your version before switching.

A model of property replication

The C++ program below models what the server's replication pass does for one actor and two connections: compare each replicated property with the last value sent to that connection, apply the condition, send the changed ones, and let the client call the RepNotify with the old value.

cpp · try it yourself
#include <cstdio>
#include <string>
#include <vector>

enum Cond { COND_None, COND_OwnerOnly, COND_SkipOwner };
struct Prop { std::string name; Cond cond; bool notify; };
const std::vector<Prop> props = { {"Health", COND_None, true}, {"Ammo", COND_OwnerOnly, false}, {"Emote", COND_SkipOwner, true} };

struct Connection {
    int id;
    std::vector<int> lastSent;     // shadow state per connection
    std::vector<int> clientCopy;   // what that client currently has
};

void replicate(const std::vector<int>& server, Connection& c, int owner, int frame) {
    bool any = false;
    for (size_t i = 0; i < props.size(); ++i) {
        const Prop& p = props[i];
        bool isOwner = c.id == owner;
        if (p.cond == COND_OwnerOnly && !isOwner) continue;
        if (p.cond == COND_SkipOwner && isOwner) continue;
        if (server[i] == c.lastSent[i]) continue;        // unchanged since the last send: skip
        int old = c.clientCopy[i];
        c.lastSent[i] = c.clientCopy[i] = server[i];
        std::printf("  frame %d -> client %d: %s = %d", frame, c.id, p.name.c_str(), server[i]);
        if (p.notify) std::printf("   (OnRep_%s, old %d)", p.name.c_str(), old);
        std::printf("\n");
        any = true;
    }
    if (!any) std::printf("  frame %d -> client %d: nothing\n", frame, c.id);
}

int main() {
    std::vector<int> server = {100, 30, 0};      // Health, Ammo, Emote
    int owner = 1;
    std::vector<Connection> conns = { {1, server, server}, {2, server, server} };

    struct Change { int frame; int prop; int value; const char* why; };
    std::vector<Change> changes = {
        {1, 1, 29, "owner fires"}, {1, 1, 28, "owner fires again"},
        {2, 0, 80, "hit for 20"},
        {3, 2, 4, "owner waves (emote 4)"},
        {4, 0, 80, "health set to the same value"},
    };
    for (int frame = 1; frame <= 4; ++frame) {
        for (const Change& ch : changes)
            if (ch.frame == frame) { server[ch.prop] = ch.value; std::printf("frame %d: %s\n", frame, ch.why); }
        for (Connection& c : conns) replicate(server, c, owner, frame);
    }
}
frame 1: owner fires
frame 1: owner fires again
  frame 1 -> client 1: Ammo = 28
  frame 1 -> client 2: nothing
frame 2: hit for 20
  frame 2 -> client 1: Health = 80   (OnRep_Health, old 100)
  frame 2 -> client 2: Health = 80   (OnRep_Health, old 100)
frame 3: owner waves (emote 4)
  frame 3 -> client 1: nothing
  frame 3 -> client 2: Emote = 4   (OnRep_Emote, old 0)
frame 4: health set to the same value
  frame 4 -> client 1: nothing
  frame 4 -> client 2: nothing

Ammo goes only to its owner and arrives once per frame however many shots happened, the health change reaches both players with the old value for the notify, the emote skips the owner (who already played it locally), and setting a property to its current value sends nothing.

Test yourself

A client sets Health = 50 on its copy of a replicated character. What happens?

  1. The server's value becomes 50
  2. Only that client's copy changes, until the next replicated update overwrites it
  3. All clients see 50
  4. The engine throws an error

Why might a client's UFUNCTION(Server, Reliable) call never run on the server?

  1. Reliable RPCs are disabled by default
  2. The client called it on an actor its connection doesn't own
  3. Server RPCs need NetMulticast too
  4. The function lacks BlueprintCallable

Which local role does a client's own pawn have?

  1. ROLE_Authority
  2. ROLE_AutonomousProxy
  3. ROLE_SimulatedProxy
  4. ROLE_None