Network models in gaming.
In game networking, particularly for engines like Unity and Unreal Engine, network models define how data is transmitted between clients and servers to enable multiplayer functionality. These models determine the architecture, synchronization, and communication strategies used in a game. Below, I’ll outline the primary types of network models commonly used in game development, with a focus on how they apply to Unity and Unreal Engine.
1. Client-Server Model
Description: A central server manages the game state and communicates with all connected clients. Clients send inputs to the server, which processes them and updates the game world, then sends the updated state back to the clients.
Key Features:
Centralized authority (server controls the game state).
Reduces cheating since clients can’t directly manipulate the game world.
Scales poorly with many players due to server load.
Unity:
Unity’s built-in networking (e.g., Unity Netcode for GameObjects, formerly MLAPI) supports a client-server model. The host can act as both a server and a client, or a dedicated server can be used.
Example: A player sends movement input to the server, which validates it and broadcasts the new position to all clients.
Unreal Engine:
Unreal’s networking is inherently client-server based. The server replicates game state (via Actor replication) to clients, and clients send inputs to the server.
Supports dedicated servers or listen servers (where one player hosts).
Example: The Character class uses replicated properties like location and health, updated by the server.
Use Case: Most traditional multiplayer games (e.g., shooters like Counter-Strike or MMOs).
2. Peer-to-Peer (P2P) Model
Description: All players (peers) communicate directly with each other without a central server. Each peer maintains its own game state and synchronizes with others.
Key Features:
Decentralized, reducing server costs.
Higher latency and synchronization issues as player count increases.
More vulnerable to cheating since there’s no central authority.
Unity:
Not natively supported by Unity’s high-level networking solutions, but can be implemented using low-level APIs (e.g., Unity Transport Layer) or third-party tools like Photon PUN.
Example: Each client sends position updates directly to other clients, with no server validation.
Unreal Engine:
Unreal does not natively support full P2P due to its focus on client-server replication. However, custom P2P solutions can be built using UDP sockets or third-party plugins.
Use Case: Small-scale games (e.g., co-op games with 2-4 players) or LAN-based games.
3. Lockstep Model
Description: All clients run the same simulation deterministically, exchanging only player inputs at fixed intervals (steps). The game state evolves identically on all machines.
Key Features:
Minimal bandwidth usage (only inputs are sent).
Requires deterministic game logic, which can be challenging to achieve with floating-point calculations or physics.
Sensitive to latency; delays from one player can stall everyone.
Unity:
Not built into Unity’s default networking but can be implemented manually with precise control over game logic and a custom networking layer.
Example: RTS games like StarCraft use this, where each client processes identical inputs (e.g., “move unit to X”).
Unreal Engine:
Unreal’s replication system isn’t designed for lockstep, as it relies on server-driven updates. Custom implementation is possible but rare due to Unreal’s focus on real-time action games.
Use Case: Strategy games or turn-based games where synchronization is critical.
4. Authoritative Server with Client Prediction
Description: An extension of the client-server model where the server has full authority, but clients predict their own state (e.g., movement) to reduce perceived latency. The server corrects discrepancies when they occur.
Key Features:
Balances responsiveness with server control.
Requires reconciliation to handle prediction errors (e.g., rubber-banding).
Unity:
Unity Netcode for GameObjects supports this through features like NetworkVariables and client-side prediction. Clients predict movement locally, and the server corrects if needed.
Example: A player moves instantly on their screen, but the server adjusts their position if they collide with a wall.
Unreal Engine:
Built into Unreal’s networking framework. The CharacterMovementComponent includes client-side prediction and server correction by default.
Example: A player jumps, and the client predicts the arc, but the server ensures they don’t clip through objects.
Use Case: Fast-paced games like first-person shooters (e.g., Unreal Tournament, Valorant).
5. Relay Server Model
Description: Clients connect through a relay server that forwards messages between them, avoiding direct P2P connections (e.g., due to NAT traversal issues).
Key Features:
Simplifies connectivity in modern networks.
Adds latency compared to direct P2P but less than a fully authoritative server.
Unity:
Unity’s Relay service (part of Unity Gaming Services) facilitates this. Clients connect via a relay server for matchmaking and communication.
Example: A co-op game where players join via a relay without hosting a dedicated server.
Unreal Engine:
Not natively provided, but third-party services (e.g., Photon Relay) or custom solutions can be integrated.
Use Case: Casual multiplayer games or when avoiding dedicated server costs.
6. State Synchronization vs. Input Synchronization
State Synchronization:
The server sends the full game state (or deltas) to clients. Common in Unity (Network Transform) and Unreal (Actor replication).
Higher bandwidth but simpler to implement.
Input Synchronization:
Clients send inputs to the server, which computes the state. Used in lockstep or deterministic systems.
Lower bandwidth but requires deterministic logic.
Unity: Supports both, depending on the networking solution (Netcode favors state sync with prediction).
Unreal: Primarily state synchronization with replication, though inputs drive server updates.
Practical Considerations in Unity and Unreal
Unity:
Offers flexibility with tools like Netcode for GameObjects, Photon, or Mirror. Developers choose the model based on game type (e.g., authoritative for competitive, relay for casual).
Lightweight and modular, but requires more manual setup for complex systems.
Unreal:
Heavily optimized for client-server with authoritative servers and replication. Best for action games needing tight synchronization.
Less flexible for alternative models like P2P or lockstep without custom work.
Summary
Unity: Commonly uses client-server (with Netcode), relay (Unity Relay), or P2P (via Photon), with support for prediction and state sync.
Unreal: Focuses on client-server with authoritative servers, replication, and prediction baked in.
Game Type: Fast-paced games lean toward authoritative models with prediction, while strategy or small-scale games might use lockstep or P2P.