[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KRC25J10G3CFFWBTA7ENP5":3,"skill-same:01M6KRC25J10G3CFFWBTA7ENP5":75},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":34,"commitSha":35,"skillDirectory":36,"forksCount":37,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":41,"updatedAt":42,"install":43,"resources":56},"01M6KRC25J10G3CFFWBTA7ENP5","multiplayer-basics",null,"Use when implementing multiplayer — MultiplayerAPI, ENet\u002FWebSocket peers, RPCs, and authority model","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28],"multiplayer","basics","multiplayer basics","websocket","model","use","implementing","authority","enet","when","2026-11-10 10:12:30",false,"---\nname: multiplayer-basics\ndescription: Use when implementing multiplayer — MultiplayerAPI, ENet\u002FWebSocket peers, RPCs, and authority model\n---\n\n# Multiplayer Basics in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs. GDScript is shown first, C# follows.\n\n**Related skills:** See **multiplayer-sync** for state synchronization and interpolation. See **dedicated-server** for headless export and server deployment.\n\n---\n\n## 1. Multiplayer Architecture\n\nGodot 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:\n\n| Peer ID | Role |\n|---------|------|\n| `1` | The server (always) |\n| `2`+ | Connected clients — randomly generated unique IDs, **not** sequential |\n\n**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 — on **every** peer, since the call is local and is not replicated.\n\n```\nServer (peer 1)\n    ├── Owns game state by default\n    ├── Spawns and validates objects\n    └── Routes RPCs\nClient (peer 2, 3, …)\n    ├── Sends input to server via RPC\n    └── Receives state updates from server\n```\n\n---\n\n## 2. Setting Up ENetMultiplayerPeer\n\nBoth 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 `MultiplayerAPI` signals (`peer_connected`, `peer_disconnected`, `connected_to_server`, `connection_failed`, plus `server_disconnected` — see §7). **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.\n\nThe server is always peer ID `1`; clients receive randomly generated unique IDs, so never assume they are sequential.\n\nFull server and client implementations with every signal handler, in GDScript and C#: [references\u002Fenet-setup.md](references\u002Fenet-setup.md)\n\n---\n\n## 3. RPCs\n\n`@rpc` (GDScript) \u002F `[Rpc]` (C#) marks a method as callable across the network. Choose the mode and transfer settings carefully — they affect both security and performance.\n\n### RPC Modes\n\n| Mode | Who may call it | Executes on |\n|------|-----------------|-------------|\n| `\"authority\"` (default) | Only the authority peer | The peer(s) it is sent to |\n| `\"any_peer\"` | Any connected peer | The peer(s) it is sent to |\n\n### Transfer Modes\n\n| Mode | Delivery | Order | Use For |\n|------|----------|-------|---------|\n| `\"reliable\"` | Guaranteed | In-order | Chat, spawn events, important state |\n| `\"unreliable\"` | Best-effort | Unordered | High-frequency position updates |\n| `\"unreliable_ordered\"` | Best-effort | In-order per channel | Smooth movement streams |\n\n### GDScript\n\n```gdscript\n# chat.gd\nextends Node2D\n\n# Any peer can call; server validates then broadcasts to all peers.\n@rpc(\"any_peer\", \"reliable\")\nfunc send_chat_message(text: String) -> void:\n\tif not multiplayer.is_server():\n\t\treturn\n\tvar sender_id := multiplayer.get_remote_sender_id()\n\t_broadcast_chat.rpc(sender_id, text)\n\n\n# Only the authority (server) can call this; runs on every peer.\n@rpc(\"authority\", \"reliable\", \"call_local\")\nfunc _broadcast_chat(sender_id: int, text: String) -> void:\n\tprint(\"[%d]: %s\" % [sender_id, text])\n\n\n# Client → server: request to spawn an object.\n@rpc(\"any_peer\", \"reliable\")\nfunc request_spawn(scene_path: String, spawn_position: Vector2) -> void:\n\tif not multiplayer.is_server():\n\t\treturn\n\t# Server validates and performs the actual spawn.\n\tvar scene: PackedScene = load(scene_path)\n\tif scene == null:\n\t\treturn\n\tvar instance := scene.instantiate()\n\tinstance.global_position = spawn_position\n\tget_tree().root.add_child(instance)\n\n\n# High-frequency sync; unreliable_ordered + a channel keeps this off other RPC traffic.\n@rpc(\"authority\", \"unreliable_ordered\", \"call_local\", 1)\nfunc sync_position(pos: Vector2) -> void:\n\tglobal_position = pos\n```\n\n**Sending to specific peers:**\n\n```gdscript\n# Send to everyone (including self if call_local is set):\nsend_chat_message.rpc(\"Hello!\")\n\n# Send to one specific peer:\nsend_chat_message.rpc_id(target_peer_id, \"Hello!\")\n```\n\n### C#\n\n```csharp\n\u002F\u002F Chat.cs\nusing Godot;\n\npublic partial class Chat : Node2D\n{\n    \u002F\u002F Any peer can call; executes on the server only.\n    [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    public void SendChatMessage(string text)\n    {\n        if (!Multiplayer.IsServer()) return;\n        int senderId = Multiplayer.GetRemoteSenderId();\n        Rpc(MethodName.BroadcastChat, senderId, text);\n    }\n\n    \u002F\u002F Authority only; runs on every peer including the caller.\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    private void BroadcastChat(int senderId, string text)\n        => GD.Print($\"[{senderId}]: {text}\");\n\n    \u002F\u002F Client → server: request a spawn.\n    [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    public void RequestSpawn(string scenePath, Vector2 spawnPosition)\n    {\n        if (!Multiplayer.IsServer()) return;\n        var scene = GD.Load\u003CPackedScene>(scenePath);\n        if (scene == null) return;\n        var instance = scene.Instantiate\u003CNode2D>();\n        instance.GlobalPosition = spawnPosition;\n        GetTree().Root.AddChild(instance);\n    }\n\n    \u002F\u002F High-frequency position sync.\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered,\n         TransferChannel = 1)]\n    public void SyncPosition(Vector2 pos)\n        => GlobalPosition = pos;\n}\n```\n\n**Sending to specific peers in C#:**\n\n```csharp\n\u002F\u002F Broadcast to all:\nRpc(MethodName.SendChatMessage, \"Hello!\");\n\n\u002F\u002F Send to one peer:\nRpcId(targetPeerId, MethodName.SendChatMessage, \"Hello!\");\n```\n\n---\n\n## 4. Authority Model\n\nEvery 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.\n\n### GDScript\n\n```gdscript\n# player.gd\nextends CharacterBody2D\n\nfunc _ready() -> void:\n\t# multiplayer.get_unique_id() = this peer's ID; server assigns authority during spawn (see Section 6).\n\tpass\n\n\nfunc _physics_process(delta: float) -> void:\n\t# Guard: authority-only input and movement.\n\tif not is_multiplayer_authority():\n\t\treturn\n\n\tvar direction := Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")\n\tvelocity = direction * 200.0\n\tmove_and_slide()\n\n\tsync_position.rpc(global_position)\n\n\n@rpc(\"authority\", \"unreliable_ordered\", \"call_local\", 1)\nfunc sync_position(pos: Vector2) -> void:\n\tif not is_multiplayer_authority():\n\t\tglobal_position = pos\n\n\nfunc print_authority_info() -> void:\n\tprint(\"My peer ID : %d\" % multiplayer.get_unique_id())\n\tprint(\"Authority  : %d\" % get_multiplayer_authority())\n\tprint(\"Am I auth? : %s\" % str(is_multiplayer_authority()))\n```\n\n### C#\n\n```csharp\n\u002F\u002F Player.cs\nusing Godot;\n\npublic partial class Player : CharacterBody2D\n{\n    public override void _PhysicsProcess(double delta)\n    {\n        \u002F\u002F Guard: authority-only input.\n        if (!IsMultiplayerAuthority()) return;\n\n        var direction = Input.GetVector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\");\n        Velocity = direction * 200f;\n        MoveAndSlide();\n\n        Rpc(MethodName.SyncPosition, GlobalPosition);\n    }\n\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered,\n         TransferChannel = 1)]\n    private void SyncPosition(Vector2 pos)\n    {\n        if (!IsMultiplayerAuthority())\n            GlobalPosition = pos;\n    }\n}\n```\n\n**API summary:**\n\n| Method | Returns | Notes |\n|--------|---------|-------|\n| `multiplayer.get_unique_id()` | `int` | This peer's ID |\n| `get_multiplayer_authority()` | `int` | ID of the peer that owns this node |\n| `is_multiplayer_authority()` | `bool` | True if this peer owns this node |\n| `set_multiplayer_authority(id)` | `void` | Transfer ownership; local only — call it on every peer (e.g. in the spawn function) |\n\n---\n\n## 5. Spawning Networked Objects\n\nUse `MultiplayerSpawner` to replicate scene instances across peers. Register the scenes (`add_spawnable_scene()` or the inspector's Auto Spawn List); when the server adds an instance of one as a direct child of the `spawn_path` node, the spawner instantiates it on every peer. For a spawn that needs data (position, owner), set `spawn_function` and call `spawn(data)` on the server.\n\n> See [references\u002Fspawning-networked-objects.md](references\u002Fspawning-networked-objects.md) for `MultiplayerSpawner` scene setup and the spawn-on-server flow (GDScript + C#).\n\n---\n\n## 6. Player Join Flow\n\nThe 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.\n\n> See [references\u002Fplayer-join-flow.md](references\u002Fplayer-join-flow.md) for the full GDScript and C# implementation (peer-connected handler, slot allocation, lobby state, gameplay transition).\n\n---\n\n## 7. Disconnect Handling\n\nListen 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 \u002F main-menu screen.\n\n> See [references\u002Fdisconnect-handling.md](references\u002Fdisconnect-handling.md) for the timeout detection settings, server-side cleanup, and client-side reconnect flow (GDScript + C#).\n\n---\n\n## 8. Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---------|---------|-----|\n| Calling an RPC on the wrong authority | Method never runs; the receiver logs `RPC '…' is not allowed on node …` | Check `is_multiplayer_authority()` before sending; use `\"any_peer\"` only where intentional |\n| Desync from unordered RPCs | Positions jitter or snap | Use `\"unreliable_ordered\"` for streams; use `\"reliable\"` for critical state changes |\n| 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 |\n| 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 |\n| Spawning without `MultiplayerSpawner` | Object appears on server, missing on clients | Add replicated instances under a `MultiplayerSpawner`'s `spawn_path` (scene in its spawnable list), or use its `spawn()` with a `spawn_function` |\n| 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 |\n| Calling `rpc()` before the client has connected | Error `Trying to call an RPC via a multiplayer peer which is not connected.` | On clients, send RPCs only after `connected_to_server` (before a peer is assigned, the default `OfflineMultiplayerPeer` runs only `call_local` RPCs, and only locally) |\n| Not stripping `res:\u002F\u002F` scenes from exported builds | Clients can read server-only scripts | Leave server-only files out of the client preset (Resources tab: export mode or exclude filters), or use PCK encryption for sensitive server code |\n\n---\n\n## 9. Checklist\n\n- [ ] `ENetMultiplayerPeer.create_server()` \u002F `create_client()` return `OK` before assigning to `multiplayer.multiplayer_peer`\n- [ ] All five multiplayer signals connected: `peer_connected`, `peer_disconnected`, `connected_to_server`, `connection_failed`, `server_disconnected`\n- [ ] Every node that reads player input guards with `if not is_multiplayer_authority(): return`\n- [ ] Input processing and `sync_position` RPC are both in `_physics_process`, not `_process`\n- [ ] RPC modes chosen deliberately: `\"any_peer\"` only for client → server calls; `\"authority\"` for server → client\n- [ ] Unreliable RPCs used only for high-frequency updates (position, rotation); reliable for events (spawn, damage, chat)\n- [ ] `MultiplayerSpawner` configured with all spawnable scenes before the first player joins\n- [ ] `set_multiplayer_authority(peer_id)` called on every peer when each player node is spawned (e.g. inside the `spawn_function`)\n- [ ] `peer_disconnected` handler frees the player node and removes it from tracking collections\n- [ ] `server_disconnected` handler on clients returns to main menu and nulls `multiplayer.multiplayer_peer`\n- [ ] `is_instance_valid()` checked before dereferencing any stored node reference in disconnect callbacks\n- [ ] No client `rpc()` calls made before `connected_to_server` fires\n","# Multiplayer Basics in Godot 4.3+\n\nAll examples target Godot 4.3+ with no deprecated APIs. GDScript is shown first, C# follows.\n\n**Related skills:** See **multiplayer-sync** for state synchronization and interpolation. See **dedicated-server** for headless export and server deployment.\n\n---\n\n## 1. Multiplayer Architecture\n\nGodot 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:\n\n| Peer ID | Role |\n|---------|------|\n| `1` | The server (always) |\n| `2`+ | Connected clients — randomly generated unique IDs, **not** sequential |\n\n**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 — on **every** peer, since the call is local and is not replicated.\n\n```\nServer (peer 1)\n    ├── Owns game state by default\n    ├── Spawns and validates objects\n    └── Routes RPCs\nClient (peer 2, 3, …)\n    ├── Sends input to server via RPC\n    └── Receives state updates from server\n```\n\n---\n\n## 2. Setting Up ENetMultiplayerPeer\n\nBoth 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 `MultiplayerAPI` signals (`peer_connected`, `peer_disconnected`, `connected_to_server`, `connection_failed`, plus `server_disconnected` — see §7). **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.\n\nThe server is always peer ID `1`; clients receive randomly generated unique IDs, so never assume they are sequential.\n\nFull server and client implementations with every signal handler, in GDScript and C#: [references\u002Fenet-setup.md](references\u002Fenet-setup.md)\n\n---\n\n## 3. RPCs\n\n`@rpc` (GDScript) \u002F `[Rpc]` (C#) marks a method as callable across the network. Choose the mode and transfer settings carefully — they affect both security and performance.\n\n### RPC Modes\n\n| Mode | Who may call it | Executes on |\n|------|-----------------|-------------|\n| `\"authority\"` (default) | Only the authority peer | The peer(s) it is sent to |\n| `\"any_peer\"` | Any connected peer | The peer(s) it is sent to |\n\n### Transfer Modes\n\n| Mode | Delivery | Order | Use For |\n|------|----------|-------|---------|\n| `\"reliable\"` | Guaranteed | In-order | Chat, spawn events, important state |\n| `\"unreliable\"` | Best-effort | Unordered | High-frequency position updates |\n| `\"unreliable_ordered\"` | Best-effort | In-order per channel | Smooth movement streams |\n\n### GDScript\n\n```gdscript\n# chat.gd\nextends Node2D\n\n# Any peer can call; server validates then broadcasts to all peers.\n@rpc(\"any_peer\", \"reliable\")\nfunc send_chat_message(text: String) -> void:\n\tif not multiplayer.is_server():\n\t\treturn\n\tvar sender_id := multiplayer.get_remote_sender_id()\n\t_broadcast_chat.rpc(sender_id, text)\n\n\n# Only the authority (server) can call this; runs on every peer.\n@rpc(\"authority\", \"reliable\", \"call_local\")\nfunc _broadcast_chat(sender_id: int, text: String) -> void:\n\tprint(\"[%d]: %s\" % [sender_id, text])\n\n\n# Client → server: request to spawn an object.\n@rpc(\"any_peer\", \"reliable\")\nfunc request_spawn(scene_path: String, spawn_position: Vector2) -> void:\n\tif not multiplayer.is_server():\n\t\treturn\n\t# Server validates and performs the actual spawn.\n\tvar scene: PackedScene = load(scene_path)\n\tif scene == null:\n\t\treturn\n\tvar instance := scene.instantiate()\n\tinstance.global_position = spawn_position\n\tget_tree().root.add_child(instance)\n\n\n# High-frequency sync; unreliable_ordered + a channel keeps this off other RPC traffic.\n@rpc(\"authority\", \"unreliable_ordered\", \"call_local\", 1)\nfunc sync_position(pos: Vector2) -> void:\n\tglobal_position = pos\n```\n\n**Sending to specific peers:**\n\n```gdscript\n# Send to everyone (including self if call_local is set):\nsend_chat_message.rpc(\"Hello!\")\n\n# Send to one specific peer:\nsend_chat_message.rpc_id(target_peer_id, \"Hello!\")\n```\n\n### C#\n\n```csharp\n\u002F\u002F Chat.cs\nusing Godot;\n\npublic partial class Chat : Node2D\n{\n    \u002F\u002F Any peer can call; executes on the server only.\n    [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    public void SendChatMessage(string text)\n    {\n        if (!Multiplayer.IsServer()) return;\n        int senderId = Multiplayer.GetRemoteSenderId();\n        Rpc(MethodName.BroadcastChat, senderId, text);\n    }\n\n    \u002F\u002F Authority only; runs on every peer including the caller.\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    private void BroadcastChat(int senderId, string text)\n        => GD.Print($\"[{senderId}]: {text}\");\n\n    \u002F\u002F Client → server: request a spawn.\n    [Rpc(MultiplayerApi.RpcMode.AnyPeer, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]\n    public void RequestSpawn(string scenePath, Vector2 spawnPosition)\n    {\n        if (!Multiplayer.IsServer()) return;\n        var scene = GD.Load\u003CPackedScene>(scenePath);\n        if (scene == null) return;\n        var instance = scene.Instantiate\u003CNode2D>();\n        instance.GlobalPosition = spawnPosition;\n        GetTree().Root.AddChild(instance);\n    }\n\n    \u002F\u002F High-frequency position sync.\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered,\n         TransferChannel = 1)]\n    public void SyncPosition(Vector2 pos)\n        => GlobalPosition = pos;\n}\n```\n\n**Sending to specific peers in C#:**\n\n```csharp\n\u002F\u002F Broadcast to all:\nRpc(MethodName.SendChatMessage, \"Hello!\");\n\n\u002F\u002F Send to one peer:\nRpcId(targetPeerId, MethodName.SendChatMessage, \"Hello!\");\n```\n\n---\n\n## 4. Authority Model\n\nEvery 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.\n\n### GDScript\n\n```gdscript\n# player.gd\nextends CharacterBody2D\n\nfunc _ready() -> void:\n\t# multiplayer.get_unique_id() = this peer's ID; server assigns authority during spawn (see Section 6).\n\tpass\n\n\nfunc _physics_process(delta: float) -> void:\n\t# Guard: authority-only input and movement.\n\tif not is_multiplayer_authority():\n\t\treturn\n\n\tvar direction := Input.get_vector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\")\n\tvelocity = direction * 200.0\n\tmove_and_slide()\n\n\tsync_position.rpc(global_position)\n\n\n@rpc(\"authority\", \"unreliable_ordered\", \"call_local\", 1)\nfunc sync_position(pos: Vector2) -> void:\n\tif not is_multiplayer_authority():\n\t\tglobal_position = pos\n\n\nfunc print_authority_info() -> void:\n\tprint(\"My peer ID : %d\" % multiplayer.get_unique_id())\n\tprint(\"Authority  : %d\" % get_multiplayer_authority())\n\tprint(\"Am I auth? : %s\" % str(is_multiplayer_authority()))\n```\n\n### C#\n\n```csharp\n\u002F\u002F Player.cs\nusing Godot;\n\npublic partial class Player : CharacterBody2D\n{\n    public override void _PhysicsProcess(double delta)\n    {\n        \u002F\u002F Guard: authority-only input.\n        if (!IsMultiplayerAuthority()) return;\n\n        var direction = Input.GetVector(\"ui_left\", \"ui_right\", \"ui_up\", \"ui_down\");\n        Velocity = direction * 200f;\n        MoveAndSlide();\n\n        Rpc(MethodName.SyncPosition, GlobalPosition);\n    }\n\n    [Rpc(MultiplayerApi.RpcMode.Authority,\n         CallLocal = true,\n         TransferMode = MultiplayerPeer.TransferModeEnum.UnreliableOrdered,\n         TransferChannel = 1)]\n    private void SyncPosition(Vector2 pos)\n    {\n        if (!IsMultiplayerAuthority())\n            GlobalPosition = pos;\n    }\n}\n```\n\n**API summary:**\n\n| Method | Returns | Notes |\n|--------|---------|-------|\n| `multiplayer.get_unique_id()` | `int` | This peer's ID |\n| `get_multiplayer_authority()` | `int` | ID of the peer that owns this node |\n| `is_multiplayer_authority()` | `bool` | True if this peer owns this node |\n| `set_multiplayer_authority(id)` | `void` | Transfer ownership; local only — call it on every peer (e.g. in the spawn function) |\n\n---\n\n## 5. Spawning Networked Objects\n\nUse `MultiplayerSpawner` to replicate scene instances across peers. Register the scenes (`add_spawnable_scene()` or the inspector's Auto Spawn List); when the server adds an instance of one as a direct child of the `spawn_path` node, the spawner instantiates it on every peer. For a spawn that needs data (position, owner), set `spawn_function` and call `spawn(data)` on the server.\n\n> See [references\u002Fspawning-networked-objects.md](references\u002Fspawning-networked-objects.md) for `MultiplayerSpawner` scene setup and the spawn-on-server flow (GDScript + C#).\n\n---\n\n## 6. Player Join Flow\n\nThe 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.\n\n> See [references\u002Fplayer-join-flow.md](references\u002Fplayer-join-flow.md) for the full GDScript and C# implementation (peer-connected handler, slot allocation, lobby state, gameplay transition).\n\n---\n\n## 7. Disconnect Handling\n\nListen 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 \u002F main-menu screen.\n\n> See [references\u002Fdisconnect-handling.md](references\u002Fdisconnect-handling.md) for the timeout detection settings, server-side cleanup, and client-side reconnect flow (GDScript + C#).\n\n---\n\n## 8. Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---------|---------|-----|\n| Calling an RPC on the wrong authority | Method never runs; the receiver logs `RPC '…' is not allowed on node …` | Check `is_multiplayer_authority()` before sending; use `\"any_peer\"` only where intentional |\n| Desync from unordered RPCs | Positions jitter or snap | Use `\"unreliable_ordered\"` for streams; use `\"reliable\"` for critical state changes |\n| 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 |\n| 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 |\n| Spawning without `MultiplayerSpawner` | Object appears on server, missing on clients | Add replicated instances under a `MultiplayerSpawner`'s `spawn_path` (scene in its spawnable list), or use its `spawn()` with a `spawn_function` |\n| 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 |\n| Calling `rpc()` before the client has connected | Error `Trying to call an RPC via a multiplayer peer which is not connected.` | On clients, send RPCs only after `connected_to_server` (before a peer is assigned, the default `OfflineMultiplayerPeer` runs only `call_local` RPCs, and only locally) |\n| Not stripping `res:\u002F\u002F` scenes from exported builds | Clients can read server-only scripts | Leave server-only files out of the client preset (Resources tab: export mode or exclude filters), or use PCK encryption for sensitive server code |\n\n---\n\n## 9. Checklist\n\n- [ ] `ENetMultiplayerPeer.create_server()` \u002F `create_client()` return `OK` before assigning to `multiplayer.multiplayer_peer`\n- [ ] All five multiplayer signals connected: `peer_connected`, `peer_disconnected`, `connected_to_server`, `connection_failed`, `server_disconnected`\n- [ ] Every node that reads player input guards with `if not is_multiplayer_authority(): return`\n- [ ] Input processing and `sync_position` RPC are both in `_physics_process`, not `_process`\n- [ ] RPC modes chosen deliberately: `\"any_peer\"` only for client → server calls; `\"authority\"` for server → client\n- [ ] Unreliable RPCs used only for high-frequency updates (position, rotation); reliable for events (spawn, damage, chat)\n- [ ] `MultiplayerSpawner` configured with all spawnable scenes before the first player joins\n- [ ] `set_multiplayer_authority(peer_id)` called on every peer when each player node is spawned (e.g. inside the `spawn_function`)\n- [ ] `peer_disconnected` handler frees the player node and removes it from tracking collections\n- [ ] `server_disconnected` handler on clients returns to main menu and nulls `multiplayer.multiplayer_peer`\n- [ ] `is_instance_valid()` checked before dereferencing any stored node reference in disconnect callbacks\n- [ ] No client `rpc()` calls made before `connected_to_server` fires\n",{"name":5,"description":7},"master","d7b26cdb5fae14d4ef7b713c5bf259395e75c3c6","skills\u002Fmultiplayer-basics",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add jame581\u002FGodotPrompter --skill multiplayer-basics",{"tool":49,"command":50},"bunx","bunx skills add jame581\u002FGodotPrompter --skill multiplayer-basics",{"tool":52,"command":53},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill multiplayer-basics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002FSKILL.md",true,[57,63,67,71],{"path":58,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002Fdisconnect-handling.md","REFERENCE","参考文档",3626,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002Freferences\u002Fdisconnect-handling.md",{"path":64,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fenet-setup.md",4358,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002Freferences\u002Fenet-setup.md",{"path":68,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Fplayer-join-flow.md",4197,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002Freferences\u002Fplayer-join-flow.md",{"path":72,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fspawning-networked-objects.md",3381,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultiplayer-basics\u002Freferences\u002Fspawning-networked-objects.md",[76,96,117,147,171,188],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":29},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[83,84,28,85,86,87,88,89,90,91,92,24,93,94,95],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":29},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[103,104,105,106,107,108,109,110,24,28,86,111,112,113,114,115,116],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":128,"publishedAt":29},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[123],{"categoryNo":124,"categoryName":125,"taxonomyType":126,"taxonomyTypeDesc":127},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[104,129,130,131,132,133,134,135,112,136,137,28,138,139,140,141,142,143,24,144,145,146],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":161,"publishedAt":29},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[153,156],{"categoryNo":154,"categoryName":155,"taxonomyType":126,"taxonomyTypeDesc":127},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":157,"categoryName":158,"taxonomyType":159,"taxonomyTypeDesc":160},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[86,162,163,164,165,24,166,167,168,169,170],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":172,"name":173,"nameZh":6,"description":174,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":175,"categories":176,"keywords":177,"publishedAt":29},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[178,179,24,180,181,182,183,184,185,186,25,28,187],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","common","sequences",{"skillNo":189,"name":190,"nameZh":6,"description":191,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":192,"categories":193,"keywords":194,"publishedAt":29},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[195,196,197,86,28,198,199,200,201,202,164,24,25,203],"state","state machine","machine","patterns","node","fsm","state machines","trade","trade-offs"]