Skip to main content
Last updated on November 30, 2026

Set up P2P transport using Godot SDK

This guide covers the Godot P2P-specific transport setup and host connection behavior for a matched game session. The SDK gives you a WebRTCMultiplayerPeer, so you can use Godot's high-level multiplayer (@rpc, MultiplayerSpawner, and MultiplayerSynchronizer) as usual.

For the shared matchmaking flow, including creating match tickets, handling match results, and joining the game session, see Integrate matchmaking (Godot). When you reach the host connection step in that guide, choose the P2P tab and use this page for the transport prerequisites.

Prerequisites​

  • Configure the match pool to use a session template with the P2P session type. See Configure P2P.
  • Set up IAM Clients with the permissions required by Matchmaking, Session V2, Lobby, and TURN Manager. Follow the steps in Manage access control for application.
  • On desktop, install the Godot WebRTC extension. It is maintained by the Godot project and is available from the Godot Asset Library and its GitHub releases. Copy it into your project's addons/webrtc folder, and then open the project once in the editor so the extension is registered. Web exports include WebRTC, so they don't need the extension.
  • Make sure that every player has logged in and connected to the Lobby. The Lobby carries the P2P signaling messages, so the game session must exist and all players must be connected before the connection starts.

Connect after joining a P2P game session​

After a match is found, one player acts as the host and the other players join the host. The usual choice is the session leader, which is the leaderID of the game session. The host gets the Godot peer ID 1, and the clients get IDs 2 and up.

extends Node

var sdk: AccelByteSDK
var p2p: AccelByteMultiplayerP2P


func connect_to_p2p_session(session_id: String) -> void:
var session: SessionService = sdk.get_session_service()
var result: Dictionary = await session.get_game_session("", session_id)
if not result.get("success", false):
print("Error GetGameSessionDetails: ", result.get("error", ""))
return

# The session leader is the host
var host_user_id: String = result.get("data", {}).get("leaderID", "")
var is_host: bool = host_user_id == sdk.get_user_id()

p2p = AccelByteMultiplayerP2P.new()
p2p.initialize(AccelByteP2PLobbySignaling.new(sdk.get_lobby_ws_service()), self, sdk.get_user_id())

# Gets the TURN and STUN credentials. Without them, only players on one network can connect.
await p2p.configure_ice_servers(sdk)

if is_host:
multiplayer.multiplayer_peer = p2p.host()
else:
p2p.connection_failed.connect(_on_connection_failed)
multiplayer.multiplayer_peer = p2p.join(host_user_id)


func _on_connection_failed(host_user_id: String, reason: String) -> void:
# Do something if the connection to the host failed
push_error("Join failed for host %s: %s" % [host_user_id, reason])

host() and join() return a WebRTCMultiplayerPeer, or null when WebRTC is not available. Assign the peer to multiplayer.multiplayer_peer at once. On a client, multiplayer.connected_to_server fires when the connection is up.

Players and IDs​

  • p2p.get_user_id(peer_id) and p2p.get_peer_id(user_id) map between AccelByte user IDs and Godot peer IDs. A client knows only the host and itself.
  • peer_user_connected(peer_id, user_id) and peer_user_disconnected(peer_id, user_id) tell you who joined or left.
  • Players may start at different times. A join that is sent before the host is listening is sent again every 2 seconds, for up to 30 seconds. If the join still fails, close the adapter, create a new one, and try again.

Design for the limits of P2P​

  • The host is a single point of failure. If the host leaves, the other players notice after roughly 20 to 25 seconds and the game ends. There is no host migration.
  • The host is trusted. The adapter doesn't check that a joining player is a member of the game session. If that matters for your game, compare the user ID from peer_user_connected with the session's members, and disconnect other players with multiplayer.multiplayer_peer.disconnect_peer(peer_id).
  • TURN is a relay. Most connections are direct. When a player's network blocks a direct connection, the traffic goes through the TURN server, which adds latency.

Troubleshooting​

SymptomLikely cause
"No default WebRTC extension configured", or host() returns nullThe WebRTC extension is not installed or not registered. Copy it to addons/webrtc and open the project once in the editor. This applies to desktop only.
The join times outThe host is not listening yet (try again), the TURN servers were not configured, or the Lobby is not connected on one side.