中EN

Networking Overview

  • Plan early for multiplayer; retrofitting requires rewriting large sections. Multiplayer gameplay still works in single-player.
  • Client-server architecture. Server holds the one, true, authoritative game state ... where the multiplayer game is actually played. Clients control remote Pawns they own on the server; send RPCs from local pawn to server pawn; server replicates state; clients simulate a close approximation. Server does not stream visuals (Pixel Streaming exists separately).
  • Each world (server, each client) has its own controllers, pawns, projectiles. Division between essential gameplay interactions, cosmetic effects, player info. Replication is not entirely automated.
  • Net modes: NM_Standalone (considered a server; no remote connections), NM_DedicatedServer (no local players; discards graphics, sound, input), NM_ListenServer (host is a player), NM_Client (no server-side logic). GetNetMode. UE_SERVER / WITH_SERVER_CODE: Game 0/1, Server 1/1, Client 0/0.
  • Listen server: easy, host advantage (fairness), extra load; for casual. Dedicated: costly, fairer, efficient; MMOs, competitive MOBAs, shooters.
  • Replication: authoritative server sending state to clients. AActor is the first class in the UObject hierarchy supported for networking. UObjects replicate only as subobjects attached to an actor.
  • Most actors do not replicate by default; set bReplicates / Replicates. Features: creation/destruction (remote proxies), movement (bReplicateMovement: Location, Rotation, Velocity), properties (when values change), components, subobjects, RPCs (Server / Client / NetMulticast).
  • Do not replicate: Skeletal/Static Mesh Component, Materials, Animation Blueprints, Particle System Component, Sound Emitters, Physics Objects — they run separately on clients; replicate driving variables.
  • Three replication systems: Generic (default; Dormancy, Priority, Relevancy), Replication Graph (plugin, scales with many actors), Iris (newest; Filtering, Prioritization).
  • Tips: as few RPCs as possible; prefer RepNotify; multicast sparingly; server-only logic need not be a server RPC; caution binding reliable RPCs to input (queue overflow); unreliable for frequent (tick) RPCs; recycle functions also as RepNotifies; check network role; IsLocallyControlled; use network dormancy — one of the most significant optimizations.

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原