Skills

Multiplayer Basics

Use when implementing multiplayer, MultiplayerAPI, ENet/WebSocket peers, RPCs, and...

Install

npx skills add jame581/GodotPrompter --skill multiplayer-basics -g -a claude-code -y
Category
Engineering
Updated
3d ago
License
MIT
Context cost
Mediumabout 3,000 tokens
Runs scripts
No, instructions only

What it does

Use when implementing multiplayer, MultiplayerAPI, ENet/WebSocket peers, RPCs, and authority model

Multiplayer Basics in Godot 4.3+

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.


1. Multiplayer Architecture

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 IDRole
1The 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, on every peer, since the call is local and is not replicated.

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 server

2. Setting Up ENetMultiplayerPeer

Both 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.

The server is always peer ID 1; clients receive randomly generated unique IDs, so never assume they are sequential.

Read the whole SKILL.md on GitHub

More in Engineering