Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use when implementing multiplayer — MultiplayerAPI, ENet/WebSocket peers, RPCs, and authority model
.claude/skills/jame581-multiplayer-basics/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | 102% | 0% |
| case-15 | ✓→✗ | ▼ Worse | 93% | 0% |
| case-09 | ✓→✓ | = Same ✓ | 208% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 42% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 64% | 0% |
All examples target Godot 4.3+ with no deprecated APIs. GDScript is shown first, C# follows.
Related skills: See multiplayer-sync for state synchronization and interpolation. See dedicated-server for headless export and server deployment.
Godot uses a client-server model built on top of MultiplayerAPI. One peer acts as the server; all others are clients. Every peer has a unique integer ID assigned by the network layer:
| Peer ID | Role | |---------|------| | 1 | The server (always) | | 2+ | Connected clients — randomly generated unique IDs, not sequential |
Multiplayer authority is the concept of ownership over a node. Only the authoritative peer should read input and drive that node's state. By default the server (peer 1) is the authority for every node. Call set_multiplayer_authority(peer_id) to transfer ownership to a client.
Server (peer 1)
├── Owns game state by default
├── Spawns and validates objects
└── Routes RPCs
Client (peer 2, 3, …)
├── Sends input to server via RPC
└── Receives state updates from serverBoth sides use the same three steps: create an ENetMultiplayerPeer, call create_server(port, max_clients) or create_client(address, port), then assign it to multiplayer.multiplayer_peer and connect the four MultiplayerAPI signals. Check the create_* return value — it returns an Error, and a silent ERR_CANT_CREATE (port already in use) otherwise looks exactly like a hang.
The server is always peer ID 1; clients receive randomly generated unique IDs, so never assume they are sequential.
Full server and client implementations with every signal handler, in GDScript and C#: references/enet-setup.md
@rpc (GDScript) / [Rpc] (C#) marks a method as callable across the network. Choose the mode and transfer settings carefully — they affect both security and performance.
| Mode | Who may call it | Executes on | |------|-----------------|-------------| | "authority" (default) | Only the authority peer | The peer(s) it is sent to | | "any_peer" | Any connected peer | The peer(s) it is sent to |
| Mode | Delivery | Order | Use For | |------|----------|-------|---------| | "reliable" | Guaranteed | In-order | Chat, spawn events, important state | | "unreliable" | Best-effort | Unordered | High-frequency position updates | | "unreliable_ordered" | Best-effort | In-order per channel | Smooth movement streams |
gdscript# chat.gd extends Node # Any peer can call; server validates then broadcasts to all peers. @rpc("any_peer", "reliable") func send_chat_message(text: String) -> void: if not multiplayer.is_server(): return var sender_id := multiplayer.get_remote_sender_id() _broadcast_chat.rpc(sender_id, text) # Only the authority (server) can call this; runs on every peer. @rpc("authority", "reliable", "call_local") func _broadcast_chat(sender_id: int, text: String) -> void: print("[%d]: %s" % [sender_id, text]) # Client → server: request to spawn an object. @rpc("any_peer", "reliable") func request_spawn(scene_path: String, spawn_position: Vector2) -> void: if not multiplayer.is_server(): return # Server validates and performs the actual spawn. var scene: PackedScene = load(scene_path) if scene == null: return var instance := scene.instantiate() instance.global_position = spawn_position get_tree().root.add_child(instance) # High-frequency sync; unreliable_ordered + a channel keeps this off other RPC traffic. @rpc("authority", "unreliable_ordered", "call_local", 1) func sync_position(pos: Vector2) -> void: global_position = pos
Sending to specific peers:
gdscript# Send to everyone (including self if call_local is set): send_chat_message.rpc("Hello!") # Send to one specific peer: send_chat_message.rpc_id(target_peer_id, "Hello!")
csharp// Chat.cs using Godot; public partial class Chat : Node { // Any peer can call; executes on the server only. [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)] public void SendChatMessage(string text) { if (!Multiplayer.IsServer()) return; int senderId = Multiplayer.GetRemoteSenderId(); Rpc(MethodName.BroadcastChat, senderId, text); } // Authority only; runs on every peer including the caller. [Rpc(MultiplayerApi.RpcMode.Authority, CallLocal = true, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)] private void BroadcastChat(int senderId, string text) => GD.Print($"[{senderId}]: {text}"); // Client → server: request a spawn. [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)] public void RequestSpawn(string scenePath, Vector2 spawnPosition) { if (!Multiplayer.IsServer()) return; var scene = GD.Load<PackedScene>(scenePath); if (scene == null) return; var instance = scene.Instantiate<Node2D>(); instance.GlobalPosition = spawnPosition; GetTree().Root.AddChild(instance); } // High-frequency position sync. [Rpc(MultiplayerApi.RpcMode.Authority, CallLocal = true, TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered, TransferChannel = 1)] public void SyncPosition(Vector2 pos) => GlobalPosition = pos; }
Sending to specific peers in C#:
csharp// Broadcast to all: Rpc(MethodName.SendChatMessage, "Hello!"); // Send to one peer: RpcId(targetPeerId, MethodName.SendChatMessage, "Hello!");
Every node has exactly one authoritative peer — the peer that is permitted to send state updates for that node. Other peers should treat incoming state as read-only.
gdscript# player.gd extends CharacterBody2D func _ready() -> void: # multiplayer.get_unique_id() = this peer's ID; server assigns authority during spawn (see Section 6). pass func _physics_process(delta: float) -> void: # Guard: authority-only input and movement. if not is_multiplayer_authority(): return var direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") velocity = direction * 200.0 move_and_slide() sync_position.rpc(global_position) @rpc("authority", "unreliable_ordered", "call_local", 1) func sync_position(pos: Vector2) -> void: if not is_multiplayer_authority(): global_position = pos func print_authority_info() -> void: print("My peer ID : %d" % multiplayer.get_unique_id()) print("Authority : %d" % get_multiplayer_authority()) print("Am I auth? : %s" % str(is_multiplayer_authority()))
csharp// Player.cs using Godot; public partial class Player : CharacterBody2D { public override void _PhysicsProcess(double delta) { // Guard: authority-only input. if (!IsMultiplayerAuthority()) return; var direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); Velocity = direction * 200f; MoveAndSlide(); Rpc(MethodName.SyncPosition, GlobalPosition); } [Rpc(MultiplayerApi.RpcMode.Authority, CallLocal = true, TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered, TransferChannel = 1)] private void SyncPosition(Vector2 pos) { if (!IsMultiplayerAuthority()) GlobalPosition = pos; } }
API summary:
| Method | Returns | Notes | |--------|---------|-------| | multiplayer.get_unique_id() | int | This peer's ID | | get_multiplayer_authority() | int | ID of the peer that owns this node | | is_multiplayer_authority() | bool | True if this peer owns this node | | set_multiplayer_authority(id) | void | Transfer ownership; call on the server |
Use MultiplayerSpawner to replicate scene instances across peers. The server adds a child to the spawned node's parent, the spawner mirrors it on every peer with synchronized state. For dynamic spawn paths, configure _spawnable_scenes and call add_child(scene.instantiate()) only on the server.
> See references/spawning-networked-objects.md for MultiplayerSpawner scene setup and the spawn-on-server flow (GDScript + C#).
The full lobby-join lifecycle: peer connects → server allocates a slot → load lobby scene → spawn player node → broadcast peer-list to all clients → on "start match" RPC, transition all peers to gameplay scene.
> See references/player-join-flow.md for the full GDScript and C# implementation (peer-connected handler, slot allocation, lobby state, gameplay transition).
Listen for peer_disconnected(id) on the multiplayer API. On the server: free the disconnected peer's player node and broadcast the updated peer-list. On clients: detect a server-disconnect and route to a reconnect / main-menu screen.
> See references/disconnect-handling.md for the timeout detection settings, server-side cleanup, and client-side reconnect flow (GDScript + C#).
| Pitfall | Symptom | Fix | |---------|---------|-----| | Calling an RPC on the wrong authority | rpc_id silently ignored; method never runs | Check is_multiplayer_authority() before sending; use "any_peer" only where intentional | | Desync from unordered RPCs | Positions jitter or snap | Use "unreliable_ordered" for streams; use "reliable" for critical state changes | | Reading input in _process vs _physics_process | Movement desyncs on different frame rates | Always move CharacterBody2D in _physics_process; send sync RPCs from there too | | Not checking is_multiplayer_authority() before input | Every peer controls every player | Add an if not is_multiplayer_authority(): return guard at the top of input handling | | Spawning without MultiplayerSpawner | Object appears on server, missing on clients | Every runtime add_child on the server that should be replicated must go through MultiplayerSpawner.spawn() | | Forgetting call_local on authority RPCs | Server state diverges from its own node | Add "call_local" when the sender also needs to execute the RPC locally | | Using rpc() before the peer is assigned | Crash or silent failure | Assign multiplayer.multiplayer_peer before calling any RPC | | Not stripping res:// scenes from exported builds | Clients can read server-only scripts | Use export_exclude or PCK encryption for sensitive server code |
ENetMultiplayerPeer.create_server() / create_client() return OK before assigning to multiplayer.multiplayer_peerpeer_connected, peer_disconnected, connected_to_server, connection_failedif not is_multiplayer_authority(): returnsync_position RPC are both in _physics_process, not _process"any_peer" only for client → server calls; "authority" for server → clientMultiplayerSpawner configured with all spawnable scenes before the first player joinsset_multiplayer_authority(peer_id) called on the server after each player node is spawnedpeer_disconnected handler frees the player node and removes it from tracking collectionsserver_disconnected handler on clients returns to main menu and nulls multiplayer.multiplayer_peeris_instance_valid() checked before dereferencing any stored node reference in disconnect callbacksrpc() calls made before multiplayer.multiplayer_peer is assigned| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-09 | pass→pass | 7,756 | 6,861 | -12% | 1 | 1 | 0% | 1,495 | 4,607 | +208% | 0 | 0 | — |
case-01 | pass→pass | 20,221 | 12,491 | -38% | 1 | 1 | 0% | 3,869 | 5,486 | +42% | 0 | 0 | — |
case-02 | fail→fail | 17,227 | 14,932 | -13% | 1 | 1 | 0% | 3,078 | 5,977 | +94% | 0 | 0 | — |
case-03 | pass→pass | 17,807 | 9,252 | -48% | 1 | 1 | 0% | 3,162 | 5,201 | +64% | 0 | 0 | — |
case-04 | pass→pass | 14,531 | 8,792 | -39% | 1 | 1 | 0% | 2,439 | 4,814 | +97% | 0 | 0 | — |
case-05 | fail→pass | 19,412 | 16,607 | -14% | 1 | 1 | 0% | 3,096 | 6,253 | +102% | 0 | 0 | — |
case-06 | pass→pass | 19,942 | 16,123 | -19% | 1 | 1 | 0% | 3,197 | 6,237 | +95% | 0 | 0 | — |
case-07 | fail→fail | 23,979 | 30,915 | +29% | 1 | 1 | 0% | 4,472 | 9,323 | +108% | 0 | 0 | — |
case-08 | pass→pass | 11,348 | 8,211 | -28% | 1 | 1 | 0% | 2,186 | 4,818 | +120% | 0 | 0 | — |
case-10 | pass→pass | 9,066 | 5,638 | -38% | 1 | 1 | 0% | 1,504 | 4,122 | +174% | 0 | 0 | — |
case-11 | pass→pass | 6,387 | 3,593 | -44% | 1 | 1 | 0% | 978 | 3,872 | +296% | 0 | 0 | — |
case-12 | pass→pass | 14,671 | 9,136 | -38% | 1 | 1 | 0% | 2,436 | 4,760 | +95% | 0 | 0 | — |
case-13 | pass→pass | 11,866 | 8,451 | -29% | 1 | 1 | 0% | 2,099 | 4,645 | +121% | 0 | 0 | — |
case-14 | pass→pass | 16,750 | 9,981 | -40% | 1 | 1 | 0% | 2,746 | 4,845 | +76% | 0 | 0 | — |
case-15 | pass→fail | 13,278 | 5,280 | -60% | 1 | 1 | 0% | 2,100 | 4,063 | +93% | 0 | 0 | — |
case-16 | pass→pass | 12,893 | 12,577 | -2% | 1 | 1 | 0% | 1,975 | 5,188 | +163% | 0 | 0 | — |
case-17 | pass→pass | 4,416 | 3,679 | -17% | 1 | 1 | 0% | 662 | 3,858 | +483% | 0 | 0 | — |
case-18 | pass→pass | 6,797 | 3,536 | -48% | 1 | 1 | 0% | 1,019 | 3,815 | +274% | 0 | 0 | — |
case-19 | pass→pass | 13,780 | 9,623 | -30% | 1 | 1 | 0% | 1,996 | 4,714 | +136% | 0 | 0 | — |
case-20 | pass→pass | 8,125 | 3,893 | -52% | 1 | 1 | 0% | 1,300 | 3,846 | +196% | 0 | 0 | — |
case-21 | pass→pass | 14,609 | 11,481 | -21% | 1 | 1 | 0% | 2,411 | 4,998 | +107% | 0 | 0 | — |
case-22 | pass→pass | 8,409 | 6,706 | -20% | 1 | 1 | 0% | 1,442 | 4,490 | +211% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of 0 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.