Skip to content

Networking and Lockstep

A SeinARTS match sends commands over the network, never state. Every machine runs the same deterministic simulation from the same starting point, and the host tells every machine which commands to run on which turn. Two machines that run the same commands in the same order end in the same state.

This keeps traffic small. A 1,000-unit battle costs the same bandwidth as an empty map, because the units are never sent. It also means a mismatch cannot be tolerated quietly: one machine that computes a different result drifts away from the others. The rest of the networking layer exists to keep that from happening, to detect it when it does, and to repair it.

The simulation advances in fixed ticks. The network groups ticks into turns. At the defaults, the simulation runs 30 ticks a second and a turn is 3 ticks, so there are 10 turns a second and one turn lasts 100 ms.

Setting Default Where
Simulation Tick Rate 30 Simulation
Turn Rate 10 Network
Input Delay Turns 3 Network

Find them in Project Settings > Plugins > SeinARTS. The tick rate must divide evenly by the turn rate. Every player in a match needs the same values: they are part of the settings hash, so a player with different values cannot join.

A turn is the list of commands that run at one turn boundary. Every machine takes turn 1, then 2, then 3, in order. A machine cannot take turn 50 until it holds turn 50, so the simulation waits at the boundary instead of running ahead.

When you right-click, the command does not run at once. It would reach other machines too late to run on the same tick everywhere. Instead each machine collects the commands its player issues during a turn and seals them for a turn Input Delay Turns ahead. Turns 1 to 3 are empty on every machine, so nothing can run in the first 0.4 seconds of a match.

Because a command also waits for the turn in progress to close, it runs between 3 and 4 turns after you issue it: 300 to 400 ms at the defaults.

The delay is also the time budget for the network. The host needs every player’s commands for a turn before it can finish that turn, and each player needs the finished turn before they reach it. A round trip that fits inside Input Delay Turns times the turn length goes unnoticed. A slower one stalls the match until the data arrives. Each extra turn of Input Delay buys one more turn length of round trip (100 ms at the defaults), up to 10 turns.

The delay does not make the game feel slow, as long as everything the player sees in response to input is immediate. Selection rings, destination markers and sounds are presentation, so they play on the click, not when the command runs. See Presentation and Visual Events.

One machine is the host. It is either a listen server, where the host also plays and has a player slot of its own, or a dedicated server, which plays no one. Clients connect only to the host. There is no peer-to-peer link between clients.

Every process runs the full simulation, a dedicated server included. Only commands cross the network.

Each connected player gets a Sein Net Relay, an actor the host spawns and gives to that player’s controller. The relay is the only road between a client and the host, so the host always knows which slot sent a message. It carries, over reliable Unreal RPCs:

  • The player’s commands up to the host, and the assembled turn back down.
  • Match start and end.
  • The host’s state, for a player who returns or falls out of sync.
  • Determinism checksums.
  • The lobby requests.

The host builds each turn like this:

  1. It waits until it holds one batch of commands for that turn from itself and from every player it still needs. A batch can be empty, and the host needs one every turn.
  2. It joins the batches in a fixed order: its own first (the host player’s commands, the match administrator’s and the AI’s), then each player slot in ascending order.
  3. It sends the same bytes to every player and runs the turn itself.

The host overwrites who a command is from. A client cannot send a command as another player, or as the match administrator.

Computer-controlled players run on the host only. The AI controller reasons on the host, and only the commands it issues are sent to other machines.

Two limits keep one player from overloading a turn. A player’s batch for one turn holds at most 512 commands and 1 MiB. A larger batch is dropped, and that turn counts as empty for the player.

The host never skips a player’s batch. If one player’s connection stalls, every machine waits at the turn boundary. A slow player cannot make the others run ahead, but they can freeze the match until Unreal closes the connection.

On the host, Get Players Holding Turn returns the players whose commands for the pending turn have not arrived. Use it for a “waiting for player” overlay. It is always empty on a client, which does not see other players’ commands.

The host stops waiting for a player once that player is defeated, and for a player whose connection dropped.

The host prepares the match from the lobby’s roster plus a random seed, builds it once the map’s actors have begun play, and sends the settings and seed to every client. Each client builds the same tick zero and reports two things: its build identity and a checksum of the state it built.

The host compares them with its own. If anything differs, the match aborts before the first tick and names the problem:

  • The host checks the build identity (the framework version, Unreal’s network version, and a hash of the simulation content), the simulation settings and the map. A player who differs in any of them fails here.
  • A different checksum with the same build means the machines built different starting states. The reason reads “Player 2 built a different tick zero.”

When every player has reported the same tick zero, all machines start ticking together. The Fixed Session Seed (0 = random) setting, under Network / Debug, replaces the random seed when it is not zero. Use it only while hunting a desync.

Every few turns (10 by default, once a second), each client sends the host a 128-bit checksum of its simulation state. The host compares it with its own checksum for the same turn. This check is the safety net: it finds a mismatch within a second, long before the players would notice units standing in different places.

The checksum covers the state the simulation reads and nothing else. Text, presentation assets and presentation-only numbers are excluded, so a player on another language setting cannot cause a mismatch.

Settings for the check, under Network:

Setting Default Effect
Determinism Checks Enabled On Turns the check on or off.
Determinism Check Interval Turns 10 Turns between checks. Set 1 while you hunt a desync.
Desync Policy Resync What the host does on a mismatch.

The two policies:

  • Resync the Peer from the Host’s State keeps the match going. The host captures its state at the next turn boundary and sends it to the player in compressed pieces. The player loads it and catches up. Nobody else notices. Use this for shipped games.
  • Abort the Match with a Report stops the match for everyone. The reason names the player and the turn, for example “Desync: player 2’s state differs from the host’s at turn 130.” Use it while developing, because a quiet repair hides the bug that caused it.

Either way, the mismatch is a bug in your game. A resync repairs the symptom and leaves the cause.

When a match aborts, the Game Mode calls On Match Aborted with the reason. By default it waits Post Match Seconds (10) and returns everyone to the lobby. Read the phase on any machine with Get Network Phase: it reports None, Starting, Running, Ended or Aborted.

Debug a Desync covers how to find the cause.

The match never waits for a dropped player. The host removes the player from the set it waits for and the match carries on. The seat’s units get no orders until someone takes the seat.

Vacant Seat Policy, under Network, decides what happens next:

Field Default Meaning
AI Takes Over On The Game Mode’s AI Controller Class plays the seat.
AI Takeover Seconds 30 Delay before the AI takes over. A few seconds ride out a network blip.
Open To New Players Off A different player may take the seat.
Open To New Players Seconds 60 Delay before a new player may take it.
Original Player Return Anytime When the player who dropped may return: Anytime, Before an AI Takes Over, or Never.

A seat with AI Takes Over and Open To New Players both off is locked. Only its own player may return, if Original Player Return allows. A seat whose player was defeated or whose result is decided gets no AI and does not open.

To decide per match or per seat, override Get Vacant Seat Policy in your Game Mode Blueprint. It runs on the host when a player drops and returns the policy for that seat.

A returning player reconnects, gets the same seat back through the lobby, and receives the host’s current state. The state is a snapshot of the world now, not the match’s history, so the time to return depends on how large the state is, not on how long the match has run. The player loads it, runs the few turns that finished while it travelled, and rejoins the turn exchange. Throughout, Is Catching Up is true on that machine. Show a “Reconnecting” overlay while it is.

While a state transfers, the match does not wait for the player. It authors commands again from the first turn the host can use.

A pause runs inside the simulation, so every machine pauses on the same tick. A paused simulation takes no turns, so a resume cannot travel inside one. It goes to the host, which sends it to every player to run in the host’s order. Request Pause and Request Resume do this for the local player.

When the simulation ends the match, it stops on that tick, and so does every machine’s. Each client reports a checksum of its final state. The host compares them, waiting at most five seconds, and then the Game Mode calls On Match Result Verified with a yes or no. Record results that matter, such as rankings or rewards, there and not in On Match Ended, because only the verified result is known to be the same everywhere.

By default, On Match Ended waits Post Match Seconds and then returns everyone to the lobby they started from.

The host also records every match it plays. See Saves and Replays.

The lobby is the screen before a match, where a host and the players it admits agree on who plays what. The framework runs the lobby; you build its screen from the Sein Lobby View Model and the SeinARTS Lobby Library. The demo builds one in Create the Main Menu and Lobby.

The lobby is a list of numbered slots. Slot N becomes player N in the match. Each slot is Open, Human, AI or Closed.

  • A player who connects takes the lowest open slot automatically.
  • The host opens and closes slots, seats an AI in a slot, sets teams, picks the map, and kicks players. Only the host may.
  • Any player toggles their own Ready.
  • The host starts the match. The framework accepts a start whenever one connected human holds a slot. Whether everyone must be ready first is your screen’s decision, as in the demo, where Start waits until everyone is ready.

When the host starts, the roster is committed and further lobby edits are refused. If a map is set, the host travels everyone to it, with the roster carried across. If no map is set, the match starts in place.

The settings, under Network / Lobby:

Setting Meaning
Available Maps The maps the lobby offers. Each entry gives the map, a display name, how many slots it has, how many teams and a thumbnail. Choosing a map resizes the lobby to its slot count.
Default Gameplay Map The map a started match travels to when the lobby has not chosen one.
Main Menu Map Where a player lands after leaving the lobby.
Reconnect Grace (seconds) How long a dropped player’s slot stays reserved in the lobby before it opens. Default 60.

When a match ends, the Game Mode returns everyone to the lobby with the same players seated, ready for a rematch.

Question Answer
Who simulates? Every process, including a dedicated server.
Who decides the order of commands? The host, every turn.
What does a client talk to? Only the host, through its own relay.
What carries the traffic? Unreal’s own networking: replicated actors and reliable RPCs.
What port? Unreal’s default, 7777 over UDP. Open it on the host’s firewall.

The Relay Actor Class setting names the relay actor. Leave it at the default. Setting it to None turns the network layer off: no relay spawns, so no commands can travel. A warning appears on screen while it is None. Networking Enabled is a separate master switch. Turn it off to ship a single-player build with the network module present.

In Project Settings > Plugins > SeinARTS, Network / PIE, Auto Start Multiplayer starts the match by itself once Unreal’s requested number of players have connected. In the editor’s Play settings, set Number of Players to 2 or more and Net Mode to Play As Listen Server. Turn Auto Start Multiplayer off to keep the match waiting until the server runs Sein.Net.StartMatch.

Editor play is not a substitute for a packaged test. An editor client window cannot be closed and launched again to rejoin its seat, so test reconnecting in a package. An editor process also has a different build identity from a packaged build, so the two cannot play the same match. See Package Your Game.

Two players play on a LAN with the defaults. At tick 361 of the match, player 2 right-clicks to send a squad across the map.

  1. Player 2’s controller turns the click into a command. Their client shows the destination marker and the squad’s selection at once, because that is presentation.
  2. The simulation is between turn 120 (tick 360) and turn 121 (tick 363). The command joins player 2’s pending batch.
  3. At tick 363 the client takes turn 121 and seals its pending commands for turn 124, three turns on. It sends the batch to the host through its relay.
  4. The host holds player 2’s batch for turn 124 along with its own, joins them (its own first, then player 2’s) and sends the finished turn to player 2.
  5. Both machines reach tick 372, the start of turn 124. Both hand the same command list to the simulation, and the squad starts moving on both machines in the same tick.

At turn 130, the next check turn, player 2’s client sends the host a checksum. It matches the host’s, so nothing else happens.

  • Reading presentation in the simulation. An actor’s position, a widget’s state or the wall clock differs between machines. Use simulation data only.
  • Using float in simulation data. Different CPUs can produce different results. Use fixed-point types.
  • Testing only in the editor. Build identity, content hash and reconnection only behave as shipped in a cooked build.
  • Leaving Auto-Start Simulation on in a menu map. The menu then runs a match nobody sees.
  • Shipping with Resync and never reading the log. A repaired desync leaves a line in the host’s log. A Shipping build writes no log by default, so read a Development host’s log before release.
  • Changing simulation settings between builds. A saved game, a replay, or a player on the old build is then rejected.