Networking (4.7)
Architecture first
- Server-authoritative. The server (or listen host) owns game state. Clients send inputs and requests, never results ("I picked up item 42", not "my gold is 9999").
- Peer IDs: the server is always
1.multiplayer.get_unique_id(),multiplayer.is_server(),multiplayer.get_peers(). Signals:peer_connected/peer_disconnected(all) andconnected_to_server/connection_failed/server_disconnected(clients). - Transports (all are
MultiplayerPeer, so swapping is trivial):ENetMultiplayerPeer(UDP, desktop and mobile, the default choice),WebSocketMultiplayerPeer(web clients; host needs TLS for https pages),WebRTCMultiplayerPeer(P2P, needs signaling), and Steam through the GodotSteam extension. - Dedicated server: export with the
dedicated_serverfeature (Export → Resources → "Dedicated Server" strips visuals) and run with--headless. Branch withOS.has_feature("dedicated_server")orDisplayServer.get_name() == "headless".
RPCs
- GDScript:
@rpc("any_peer" | "authority", "call_local" | "call_remote", "reliable" | "unreliable" | "unreliable_ordered", channel). Call withrpc(&"method", args)(everyone) orrpc_id(peer, &"method", args). The default@rpcis authority-only, call_remote and reliable. - C#:
[Rpc(MultiplayerApi.RpcMode.AnyPeer, CallLocal = true, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)], thenRpc(MethodName.Fire, dir)/RpcId(1, MethodName.Fire, dir). - The method must exist with the same RPC config on every peer, at the same node path. Spawn replicated nodes through MultiplayerSpawner so names and paths match.
- Inside an RPC,
multiplayer.get_remote_sender_id()tells you who called. Validate everyany_peerRPC on the server: is the sender allowed, is the value sane, is it rate-limited? - Use
unreliablefor frequent state (positions),reliablefor events (damage, chat, spawn requests) andunreliable_orderedfor streams where old packets are useless. Use separate channels for unrelated reliable streams so they don't block each other.
Replication nodes (prefer them to hand-written RPC sync)
MultiplayerSpawner: setspawn_path(the parent node) andadd_spawnable_scene("res://player.tscn"), or aspawn_functionfor custom data. Only the authority adds children (or callsspawn(data)), and clients get them automatically. Thespawnedsignal fires on clients.MultiplayerSynchronizer: setroot_pathand a replication config with properties such as.:positionandSprite2D:flip_h. Each property has a mode: spawn-only,ON_CHANGE(watch) orALWAYS(sync). Tunereplication_interval/delta_interval. Control interest withpublic_visibility = false+set_visibility_for(peer, true)oradd_visibility_filter(callable).- Authority: call
set_multiplayer_authority(peer_id)on a player's node (recursive by default) so that client's input synchronizer sends its data. Checkis_multiplayer_authority()before reading local input. A common split is client authority over an input-only synchronizer node while the server keeps authority over state. - Smooth remote entities: interpolate received positions toward the latest snapshot in
_process, or buffer two snapshots. Never snap.
Auth and safety
SceneMultiplayer.auth_callback+send_auth/complete_authruns a handshake (version check, token) before a peer counts as connected.- Keep
SceneMultiplayer.allow_object_decoding = false(the default). Never send Objects or Resources over the network. - Never
load()paths orstr_to_vardata that came from peers. Don'tcall()method names received from the network. - Limit how many players can connect (
create_server(port, max_clients)), and handle disconnects mid-game: despawn their nodes on the server.
HTTP and web APIs
HTTPRequestnode:request(url, headers, method, body), thenrequest_completed(result, code, headers, body). Parse withJSON.parse_string(body.get_string_from_utf8()). Use one request at a time per node (create more nodes for parallel requests), and settimeout.- TLS is automatic for https. For custom CAs use
TLSOptions.client(trusted_cert). - Lower level:
HTTPClient(streaming),WebSocketPeer(connect_to_url, callpoll()every frame),StreamPeerTCP(4.6+:poll()/get_status()live onStreamPeerSocket),PacketPeerUDPandStreamPeerUDS(Unix sockets, 4.6+). - Never ship secret API keys in the client. Route them through your own backend.
Testing locally
Debug → "Customize Run Instances" in the editor can launch several instances with different arguments (--server, --client). From the CLI, start one headless server process plus GUI clients. run_godot.py smoke covers a headless server boot.
Lobby (ENet host/join), spawner + synchronizer player, validated RPCs, HTTP client, C# RPCs (compiled by the tests): references/patterns.md


