Skip to main content

Rollback Overview

AFT uses rollback netcode. Every peer simulates the match locally with the inputs it has and predicts the missing remote inputs (it repeats the last one). When the real input arrives and differs from the prediction, the peer loads the saved state of that frame and re-simulates up to the present in the same tick. Players see their own inputs immediately, whatever the latency.

The AFTRollback module is a clean, Unreal native implementation:

  • no global state and no C callbacks: IAFTRollbackSession and IAFTRollbackHandler (save, load, advance, events);
  • explicit little-endian serialization of every message (no packed structs or bitfields, which differ between compilers), validation of every incoming packet (size, type, magic, protocol version, sequence), preallocated buffers (no allocation per frame);
  • pluggable transports (IAFTNetTransport): Unreal sockets (platform UDP, EOS P2P, Steam sockets), in-process loopback, and a conditioner that simulates latency, jitter and packet loss.

Why it works: the deterministic simulation​

Rollback needs a simulation that gives exactly the same result for the same inputs on every machine, and that can be saved and restored cheaply. In AFT:

  • the whole match state (FAFTSimState) is a plain struct without padding: saving a frame is one memcpy, the checksum is a CRC of its bytes;
  • the simulation uses fixed-point integer math only (FAFTFixed, 1/1000 cm), never reads the world and never touches actors;
  • the assets are compiled into a read-only database at battle start (FAFTSimDatabase) with a content hash.

See Writing Deterministic Code before you change the gameplay code.

Net modes​

The net mode is part of the match config (FAFTMatchConfig.NetMode, EAFTNetMode):

ModeSessionUse
OfflinenoneLocal play, no rollback.
SyncTestsync test sessionEvery frame is rolled back and re-simulated, checksums compared: non deterministic code is reported on the frame it happens.
LoopbackRollback2 P2P sessions on a virtual networkThe full online path on one machine: the second peer runs inside the battle session, with simulated latency / jitter / loss.
OnlineP2P sessionTwo machines, one local and one remote player.
Spectatorspectator sessionReceives the confirmed inputs of a host.

The battle session (FAFTBattleSession) hides these modes behind one API: the rest of the game does not care whether the match is offline or online.

Defaults​

SettingValue
Prediction frames8
Frame delay online2 (AFT Game > Online > Online Frame Delay, 0 to 8)
Disconnect timeout5 s
Disconnect notificationafter 750 ms without packets
Desync checkchecksum of the confirmed frames every 30 frames

Frame delay adds a few frames of input delay so that most remote inputs arrive before they are needed: fewer rollbacks, at the cost of a little latency. Time sync slows down the peer that is ahead so that neither side rolls back more than the other.

Safety checks​

  • Content check: the session refuses a peer with a different protocol version or a different game hash (content hash of the compiled database + match seed). Two players with different fighter data or rules cannot play together.
  • Desync detection: peers exchange the checksum of confirmed frames and raise DesyncDetected; the result reports it (FAFTMatchResult.bDesynced) and the HUD can display it.

Network stats​

UAFTBattleSubsystem::GetNetworkStats (FAFTRollbackNetworkStats) and GetLastRollbackFrames give the ping, the rollback length and the frame advantage, and OnSessionStatusChanged reports the session status (connecting, running, interrupted, disconnected...). The default battle HUD shows them during online matches.

Next: Testing the Netcode and Online Backends.