Steam lobbies and multiplayer in Godot

2 min read

By Eduardo Orellana ·

To put a Godot game online through Steam: create a lobby with Steam.createLobby(type, max_members) and wait for lobby_created; let friends join through the overlay with Steam.activateGameOverlayInviteDialog(lobby_id) and handle join_requested; find public lobbies with Steam.requestLobbyList() and lobby_match_list; then run Godot's high-level multiplayer over Steam with GodotSteam's SteamMultiplayerPeer. Players need no port forwarding, and Steam relays the traffic.

Steam solves the hardest part of indie multiplayer: finding each other

Most indie multiplayer games are played with friends. Steam already knows who your friends are, lets them click Join Game, and relays the traffic so nobody opens a port. GodotSteam exposes all of it to GDScript.

Create and join a lobby

A lobby is Steam's meeting room: up to 250 members, private, friends-only, public or invisible.

func host() -> void:
	Steam.lobby_created.connect(_on_lobby_created)
	Steam.createLobby(Steam.LOBBY_TYPE_FRIENDS_ONLY, 4)

func _on_lobby_created(result: int, lobby_id: int) -> void:
	if result == Steam.RESULT_OK:
		Steam.setLobbyData(lobby_id, 'name', 'My lobby')
		Steam.activateGameOverlayInviteDialog(lobby_id)

func _ready() -> void:
	Steam.join_requested.connect(func(lobby_id: int, _friend: int) -> void: Steam.joinLobby(lobby_id))
	Steam.lobby_joined.connect(_on_lobby_joined)

Join Game, invites and lists

  • Invites: activateGameOverlayInviteDialog() opens Steam's friend picker. It may not work when the game was not launched from Steam.
  • Join Game from a friend's profile fires join_requested if the game is running; if it is not, Steam launches it with +connect_lobby <lobby id> on the command line.
  • Public lobbies: add filters, call requestLobbyList(), read results in lobby_match_list (up to 50).
  • Closing a lobby: setLobbyJoinable(false) once the match starts.

Carrying the game: SteamMultiplayerPeer

Once everyone is in the lobby, GodotSteam's SteamMultiplayerPeer lets Godot's normal high-level multiplayer (MultiplayerSpawner, MultiplayerSynchronizer, RPCs) run over Steam's networking: create a host peer on the lobby owner and client peers on the others, then assign it to multiplayer.multiplayer_peer. Your game code stays standard Godot.

Where Flockbay fits

In Flockbay, you can test multiplayer with a friend through join-code rooms while you build, free on every account. For the shipped game on Steam, Flockbay's AI writes GodotSteam into it as an ordinary autoload you own: the lobby, the overlay invite, Join Game and SteamMultiplayerPeer, standing down while a Flockbay room is the peer. Nothing of Flockbay's ships in your game.

Questions

Do players need to port forward for Steam multiplayer in Godot?
No. Steam's networking relays the connection through SteamMultiplayerPeer.
How many players can a Steam lobby hold?
Up to 250, according to GodotSteam's lobby documentation.

Flockbay

The free AI game maker for Windows, macOS and Linux.