godot-adapt-single-to-multiplayer

$npx mdskill add thedivergentai/GD-Agentic-Skills/godot-adapt-single-to-multiplayer

Retrofit multiplayer into single-player Godot games with authoritative server patterns.

  • Solves adding online multiplayer to existing single-player games.
  • Depends on MultiplayerPeer, ENetMultiplayerPeer, and MultiplayerSynchronizer.
  • Recommends authoritative server design and never trusting client state.
  • Delivers code patterns for lag compensation, input buffering, and anti-cheat.

SKILL.md

.github/skills/godot-adapt-single-to-multiplayerView on GitHub ↗
---
name: godot-adapt-single-to-multiplayer
description: "Expert patterns for adding multiplayer to single-player games including client-server architecture, authoritative server design, MultiplayerSynchronizer, lag compensation (client prediction, server reconciliation), input buffering, and anti-cheat measures. Use when retrofitting multiplayer, porting to online play, or designing networked gameplay. Trigger keywords: MultiplayerPeer, ENetMultiplayerPeer, SceneMultiplayer, MultiplayerSynchronizer, rpc, rpc_id, multiplayer_authority, client_prediction, server_reconciliation, lag_compensation, rollback."
---

## Godot 4.7 Baseline

- Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18).
- Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6.
- **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes.

# Adapt: Single to Multiplayer

Expert guidance for retrofitting multiplayer into single-player games.

## NEVER Do (Expert Multiplayer Rules)

### Security & Authority
- **NEVER trust client-reported state** — Clients own their 'Input', NOT their 'Position' or 'Health'. Server must validate every coordinate and health change.
- **NEVER use `get_tree()` groups for authority checks** — Use `is_multiplayer_authority()`. Group registration is non-deterministic in high-latency joins.
- **NEVER allow unrestricted RPC rates** — A malicious client can call a 'FireWeapon' RPC 10,000 times per second. Always implement rate-limiting (`net_rpc_rate_limiter.gd`).

### Movement & Lag
- **NEVER skip Client-Side Prediction** — Movement without prediction feels 'heavy' and unresponsive. Predict movement locally, then correct only on server disagreement.
- **NEVER sync peers at 60Hz** — Sending entire state every frame will saturate client bandwidth. Use a lower tick-rate (20-30Hz) and interpolate between packets.
- **NEVER snap peer positions** — Abrupt position updates cause 'jitter'. Store a buffer of past states and lerp between them with a 100ms delay.

### Bandwidth & Sync
- **NEVER sync 'Full Floats' if possible** — Quantize Vector3 data (truncating decimals) to save 50%+ bandwidth. Use `MultiplayerSynchronizer` with delta-sync enabled.
- **NEVER ignore 'Late Joiners'** — Players who join mid-game won't see existing environmental changes. Broadcast a full world-state 'Snapshot' on peer connection.
- **NEVER test on 0ms ping** — Everything works on localhost. Use a simulator (`net_latency_simulator.gd`) with 150ms ping to identify sync bugs.

---

## Available Scripts

> **MANDATORY**: Architecture decision tree first, then golden-path scripts. Deep latency workflows → [`references/latency-testing.md`](references/latency-testing.md).

### Authority / transport bridges
### [multiplayer_sync.gd](scripts/multiplayer_sync.gd)
**MANDATORY** when adding `MultiplayerSynchronizer` interpolation for remote peers. Trigger: authority owns transforms; non-authority interpolates.

### [rpc_bridge.gd](scripts/rpc_bridge.gd)
**MANDATORY** signal→RPC bridge. Trigger: gameplay emits local signals; bridge validates authority and fans out RPCs.

### Prediction / lag / lobby
### [net_prediction_reconciliation.gd](scripts/net_prediction_reconciliation.gd)
CharacterBody prediction + input-buffer replay for server reconciliation.

### [net_snapshot_interpolation.gd](scripts/net_snapshot_interpolation.gd)
Snapshot interpolation / jitter buffers for remote peers.

### [net_auth_server_validator.gd](scripts/net_auth_server_validator.gd)
Authoritative validation (position, speed, actions).

### [net_rpc_rate_limiter.gd](scripts/net_rpc_rate_limiter.gd)
RPC flood / macro protection.

### [net_interest_management.gd](scripts/net_interest_management.gd)
Distance-based visibility to cut bandwidth.

### [net_delta_compression_sync.gd](scripts/net_delta_compression_sync.gd)
Quantization + significance checks for delta sync.

### [net_lag_compensation.gd](scripts/net_lag_compensation.gd)
Server-side rewind for hit registration.

### [net_lobby_late_join_sync.gd](scripts/net_lobby_late_join_sync.gd)
Late-joiner world snapshot bootstrap.

### Diagnostics
### [net_latency_simulator.gd](scripts/net_latency_simulator.gd)
**MANDATORY** before ship — see [`references/latency-testing.md`](references/latency-testing.md).

### [net_debug_overlay_monitor.gd](scripts/net_debug_overlay_monitor.gd)
RTT / loss / jitter overlay.

### [net_upnp_discovery_logic.gd](scripts/net_upnp_discovery_logic.gd)
UPNP port mapping for listen-server / P2P hosts.

---

## Architecture Patterns

| Pattern | When | Script golden path |
|---------|------|--------------------|
| Authoritative server | PvP, economies, cheat risk | `rpc_bridge.gd` → `net_auth_server_validator.gd` → prediction/recon |
| P2P lockstep | 2–4 co-op, low cheat risk | Deterministic inputs + `net_upnp_discovery_logic.gd` |
| Hybrid / host authority | Party games 4–8 | Host authority + late-join snapshot |

---

## Migration golden path (no inline host/join tutorials)

1. Separate **input** (client) from **simulation** (authority).
2. Set `multiplayer_authority` per player node; clients send intents only.
3. **MANDATORY** `multiplayer_sync.gd` for property replication / remote interpolation.
4. **MANDATORY** `rpc_bridge.gd` for gameplay events that cross the wire.
5. Add prediction / lag compensation scripts only for the genres that need them.
6. Validate with **latency-testing** reference + `net_latency_simulator.gd` at ~150 ms RTT.

## Expert insights (WHY — keep in body)

- **Client prediction** — WHY: without local sim, RTT doubles perceived input lag. Replay buffered inputs after server correction ([net_prediction_reconciliation.gd](scripts/net_prediction_reconciliation.gd)).
- **Interpolation buffer** — WHY: raw sync packets jitter; lerp between snapshots with ~100 ms delay ([net_snapshot_interpolation.gd](scripts/net_snapshot_interpolation.gd)).
- **Hit rewind** — WHY: clients fire at past world state; server rewinds RIDs via `PhysicsServer3D` before raycast ([net_lag_compensation.gd](scripts/net_lag_compensation.gd)).
- **Input send rate** — WHY: 60 Hz input RPCs saturate uplink; batch at 20–30 Hz with significance checks ([net_delta_compression_sync.gd](scripts/net_delta_compression_sync.gd)).

## Decision Tree: Which Architecture?

| Factor | Authoritative Server | P2P Lockstep |
|--------|---------------------|--------------|
| Player count | 8-100+ | 2-4 |
| Cheat prevention | Critical | Not important |
| Server hosting | Available | Not available |
| Gameplay type | PvP, competitive | Co-op, casual |
| Lag tolerance | Medium (prediction helps) | Low (desyncs) |
| Development complexity | High | Medium |


## Advanced Networking Topics

### Peer-to-Peer NAT Traversal (Hole Punching)
In P2P architectures, clients often sit behind firewalls. **UPNP** (Universal Plug and Play) is the first line of defense, allowing the game to request port forwarding from the router automatically using `net_upnp_discovery_logic.gd`.

For cases where UPNP fails:
- **STUN/TURN**: Use a STUN server to discover public IP/port pairings.
- **Relay Servers**: If direct connection is impossible, fallback to a relay server (TURN) to bridge the two peers.

### Network Profiling & Visualization
Visualizing the packet timeline is critical for debugging jitter. Propose an overlay that graphs:
- **Packet Arrival**: A scrolling timeline showing when packets arrive relative to physics frames.
- **Buffer Health**: A visualization of the interpolation jitter buffer size.
- **RTT (Round Trip Time)**: Real-time graph of latency spikes.

## Deep recipes (on demand)

| Topic | Reference / script |
|-------|-------------------|
| Prediction / recon / interpolation | [prediction-and-reconciliation.md](references/prediction-and-reconciliation.md) |
| Authority / anti-cheat / bandwidth | [authority-and-security.md](references/authority-and-security.md) |
## Reference

> Progressive disclosure: open Official Documentation links only when researching a specific API;
> load Related Skills when routing work to a peer domain — do not preload the whole lattice.

### Official Documentation
- [High-level multiplayer](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html) — RPC modes, authority, and peer lifecycle you must retrofit before any gameplay state leaves the single-player path.
- [Networking](https://docs.godotengine.org/en/stable/tutorials/networking/index.html) — Transport map (ENet / WebSocket / WebRTC) so host/join choices match platform and NAT constraints.
- [MultiplayerSynchronizer](https://docs.godotengine.org/en/stable/classes/class_multiplayersynchronizer.html) — Property replication, delta sync, and visibility filters that replace ad-hoc position RPCs.
- [MultiplayerSpawner](https://docs.godotengine.org/en/stable/classes/class_multiplayerspawner.html) — Spawn/despawn replication when late joiners need the same scene graph as the host.
- [SceneMultiplayer](https://docs.godotengine.org/en/stable/classes/class_scenemultiplayer.html) — Default MultiplayerAPI implementation: root path, auth callbacks, and RPC routing under SceneTree.
- [ENetMultiplayerPeer](https://docs.godotengine.org/en/stable/classes/class_enetmultiplayerpeer.html) — UDP host/client peer used by most LAN and dedicated-server ports of single-player games.
- [MultiplayerAPI](https://docs.godotengine.org/en/stable/classes/class_multiplayerapi.html) — `multiplayer` singleton surface: peer IDs, signals, and `rpc` / `rpc_id` entry points.
- [MultiplayerPeer](https://docs.godotengine.org/en/stable/classes/class_multiplayerpeer.html) — Transfer modes and connection status shared by every concrete peer backend.
- [UPNP](https://docs.godotengine.org/en/stable/classes/class_upnp.html) — Automatic port mapping for listen-server / P2P hosts behind consumer routers.
- [WebRTC](https://docs.godotengine.org/en/stable/tutorials/networking/webrtc.html) — Browser-friendly P2P path when ENet UDP cannot punch through firewalls alone.
- [Node](https://docs.godotengine.org/en/stable/classes/class_node.html) — `set_multiplayer_authority` / `is_multiplayer_authority` ownership rules for input vs state.
- [PhysicsServer3D](https://docs.godotengine.org/en/stable/classes/class_physicsserver3d.html) — Direct RID transforms for server-side hit rewind without SceneTree side effects.

### Related Skills

#### Prerequisites
- [godot-input-handling](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-input-handling/SKILL.md) — Split InputMap reads from simulation so clients send intents and the authority owns outcomes.
- [godot-signal-architecture](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-signal-architecture/SKILL.md) — Local signal graphs that `rpc_bridge.gd` can wrap without coupling gameplay to transport.
- [godot-autoload-architecture](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-autoload-architecture/SKILL.md) — Session/lobby Autoloads that outlive scene changes during host/join flow.

#### Complements
- [godot-multiplayer-networking](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-multiplayer-networking/SKILL.md) — Broader RPC, lobby, and ENet tuning once the single-player→online migration shape is fixed.
- [godot-characterbody-2d](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-characterbody-2d/SKILL.md) — Deterministic move_and_slide steps reused by client prediction and reconciliation buffers.
- [godot-physics-3d](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-physics-3d/SKILL.md) — Body/shape setup that lag-compensation rewind and hit validation query against.
- [godot-raycasting-queries](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-raycasting-queries/SKILL.md) — Server-side ray/shape queries for authoritative shots after state rewind.
- [godot-debugging-profiling](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-debugging-profiling/SKILL.md) — RTT/jitter overlays and remote debug habits that catch sync bugs localhost never shows.
- [godot-export-builds](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-export-builds/SKILL.md) — Headless/dedicated-server export presets and CLI flags for real multi-instance tests.
- [godot-server-architecture](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-server-architecture/SKILL.md) — PhysicsServer/RID patterns and headless host scaffolding used by rewind and dedicated peers.

#### Downstream / consumers
- [godot-genre-shooter-fps](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-genre-shooter-fps/SKILL.md) — Hitscan/projectile feel that depends on prediction + lag compensation from this skill.
- [godot-genre-battle-royale](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-genre-battle-royale/SKILL.md) — Large-peer interest management and late-join snapshots at BR scale.
- [godot-monte-carlo-balancer](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-monte-carlo-balancer/SKILL.md) — Retune economy/TTK after netcode changes alter effective weapon timings.
- [godot-performance-optimization](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-performance-optimization/SKILL.md) — Cap replication rate and cull interest when bandwidth/CPU budgets break under peer load.

#### Master
- [godot-master](https://github.com/thedivergentai/gd-agentic-skills/blob/main/skills/godot-master/SKILL.md) — Library router and mirrored module entry for this Domain Skill.

More from thedivergentai/GD-Agentic-Skills

SkillDescription
godot-2d-animationExpert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs. Use when implementing sprite frame animations, procedural animation (squash/stretch), cutout bone hierarchies, or frame-perfect timing systems. Trigger keywords: AnimatedSprite2D, SpriteFrames, animation_finished, animation_looped, frame_changed, frame_progress, set_frame_and_progress, cutout animation, skeletal 2D, Bone2D, procedural animation, animation state machine, advance(0).
godot-2d-physicsExpert patterns for Godot 2D physics including collision layers/masks, Area2D triggers, raycasting, and PhysicsDirectSpaceState2D queries. Use when implementing collision detection, trigger zones, line-of-sight systems, or manual physics queries. Trigger keywords: CollisionShape2D, CollisionPolygon2D, collision_layer, collision_mask, set_collision_layer_value, set_collision_mask_value, Area2D, body_entered, body_exited, RayCast2D, force_raycast_update, PhysicsPointQueryParameters2D, PhysicsShapeQueryParameters2D, direct_space_state, move_and_collide, move_and_slide.
godot-3d-lightingExpert patterns for Godot 3D lighting including DirectionalLight3D shadow cascades, OmniLight3D attenuation, SpotLight3D projectors, VoxelGI vs SDFGI, and LightmapGI baking. Use when implementing realistic 3D lighting, shadow optimization, global illumination, or light probes. Trigger keywords: DirectionalLight3D, OmniLight3D, SpotLight3D, shadow_enabled, directional_shadow_mode, directional_shadow_split, omni_range, omni_attenuation, spot_range, spot_angle, VoxelGI, SDFGI, LightmapGI, ReflectionProbe, Environment, WorldEnvironment.
godot-3d-materialsExpert patterns for Godot 3D PBR materials using StandardMaterial3D including albedo, metallic/roughness workflows, normal maps, ORM texture packing, transparency modes, and shader conversion. Use when creating realistic 3D surfaces, PBR workflows, or material optimization. Trigger keywords: StandardMaterial3D, BaseMaterial3D, albedo_texture, metallic, metallic_texture, roughness, roughness_texture, normal_texture, normal_enabled, orm_texture, transparency, alpha_scissor, alpha_hash, cull_mode, ShaderMaterial, shader parameters.
godot-3d-world-buildingExpert patterns for 3D level design using GridMap with MeshLibrary, CSG constructive solid geometry, occlusion, and runtime GridMap builders. Use when building 3D levels, modular tilesets, or BSP-style geometry. For sky/fog/Environment recipes, route to godot-3d-lighting. Trigger keywords: GridMap, MeshLibrary, set_cell_item, get_cell_item, map_to_local, local_to_map, CSGCombiner3D, CSGBox3D, CSGSphere3D, CSGPolygon3D, OccluderInstance3D, bake CSG.
godot-ability-systemExpert patterns for RPG/action ability systems including cooldown strategies, combo systems, ability chaining, skill trees with prerequisites, upgrade paths, and resource management. Use when implementing unlockable abilities, character progression, or complex skill systems. Trigger keywords: PlayerAbility, AbilityManager, cooldown, SkillTree, SkillNode, prerequisites, can_use, execute, ComboSystem, ability_chain, global_cooldown, charge_system, upgrade_path.
godot-adapt-2d-to-3dExpert patterns for migrating 2D games to 3D including node type conversions, camera systems (third-person, first-person, orbit), physics layer migration, sprite-to-model art pipeline, and control scheme adaptations. Use when porting 2D projects to 3D or adding 3D elements. Trigger keywords: CharacterBody2D to CharacterBody3D, Area2D to Area3D, Camera2D to Camera3D, Vector2 to Vector3, collision_layer migration, sprite to MeshInstance3D, 2D to 3D conversion.
godot-adapt-3d-to-2dExpert patterns for simplifying 3D games to 2D including dimension reduction strategies, 2.5D fake-depth, isometric ports, camera flattening, physics conversion, 3D-to-sprite art pipeline, and control simplification. Use when porting 3D to 2D, building 2.5D / isometric / fake-depth gameplay, creating 2D versions for mobile, or prototyping. Trigger keywords: CharacterBody3D to CharacterBody2D, Camera3D to Camera2D, Vector3 to Vector2, flatten Z-axis, 2.5D, isometric, fake depth, Y-sort, simulated Z, orthogonal projection, 3D to sprite conversion, performance optimization.
godot-adapt-desktop-to-mobileExpert patterns for porting desktop games to mobile including touch control schemes (virtual joystick, gesture detection), UI scaling for small screens, performance optimization for mobile GPUs, battery life management, and platform-specific features. Use when creating mobile ports or cross-platform mobile builds. Trigger keywords: TouchScreenButton, virtual_joystick, gesture_detector, InputEventScreenTouch, InputEventScreenDrag, mobile_optimization, battery_saving, adaptive_performance, MOBILE_ENABLED.
godot-adapt-mobile-to-desktopExpert patterns for scaling mobile games to desktop including mouse/keyboard controls, increased resolution and graphical fidelity, expanded UI layouts, settings menus, window management, and platform-specific features. Use when creating desktop ports or cross-platform releases. Trigger keywords: mouse_controls, keyboard_shortcuts, resolution_scaling, graphics_settings, fullscreen_toggle, window_modes, Steam_integration, desktop_optimization.