How heroiclabs/nakama-godot-demo works
Purpose and runnable projects
This repository is a multiplayer Godot platformer/demo for Nakama: account authentication, persisted character customization, realtime chat, notifications, and synchronized player movement. The complete runnable client is rooted at godot/project.godot; its main scenes are godot/src/Main/MainMenu.tscn and godot/src/Main/GameWorld.tscn. A smaller learning-oriented variant lives under tutorial/godot/project.godot.
Client composition and scene flow
The Godot client transitions from login/registration to character management and then the shared game world. Main-menu orchestration is in godot/src/Main/MainMenu.gd; authentication forms are godot/src/UI/LoginAndRegister.gd, godot/src/UI/Menus/Login/LoginForm.gd, and godot/src/UI/Menus/Register/RegisterForm.gd. The world scene and lifecycle are godot/src/Main/GameWorld.gd and godot/src/Main/GameWorld.tscn.
Process-wide application services
Godot autoloads provide the application boundary between UI/gameplay and Nakama. godot/src/Autoload/ServerConnection.gd owns client/session/socket connectivity; delegate classes separate authentication, storage, and exception concerns in godot/src/Autoload/Delegates/Authenticator.gd, godot/src/Autoload/Delegates/StorageWorker.gd, and godot/src/Autoload/Delegates/ExceptionHandler.gd. godot/src/Autoload/GameControls.gd centralizes user/game control state.
Identity, characters, and persistence
After email/password authentication, character screens create, list, select, and edit a player profile, including color. The character UI pipeline is centered on godot/src/UI/Menus/Characters/CharacterMenu.gd, godot/src/UI/Menus/Characters/CharacterCreator.gd, and godot/src/UI/Menus/Characters/CharacterColorEditor.gd. Persistence crosses the client/server boundary through the storage delegate and Nakama storage-object API models, notably godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd.
Realtime gameplay and communication
The world represents local and remote players through godot/src/World/Characters/Player.gd, godot/src/World/Characters/Character.gd, and godot/src/World/Level.gd. Client gameplay and UI feed socket events through godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd; chat is presented by godot/src/UI/ChatBox.gd, while notification display is coordinated by godot/src/UI/Components/NotificationList.gd and godot/src/UI/Elements/Notification.gd.
Nakama client integration boundary
The repository vendors the Godot Nakama client addon rather than relying on a package-resolution step. Its public facade/client transport layers are godot/addons/com.heroiclabs.nakama/Nakama.gd, godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd, and godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd. This layer handles HTTP API calls, session models, serialization, and WebSocket realtime transport, insulating game scripts from protocol details.
Server runtime and authoritative RPCs
Local infrastructure is Docker Compose in nakama/docker-compose.yml, running Nakama with CockroachDB. Server-side Lua modules implement world control and RPC behavior in nakama/modules/world_control.lua and nakama/modules/world_rpc.lua; these are the backend extension boundary for synchronized world interactions. Nakama also exposes its admin interface locally. The tutorial has a parallel, self-contained server setup at tutorial/nakama/docker-compose.yml and a reduced client/server code path.
Main entry points: ServerConnection.gd Server Connection · docker-compose.yml Nakama Runtime · NakamaSocket.gd Nakama Socket · MainMenu.gd Main Menu
Components 21
Godot Client
Runnable multiplayer client.
- Main Menu · Routes login, characters, and world entry.
godot/src/Main/MainMenu.gd - Login & Registration
godot/src/UI/LoginAndRegister.gd - Character Management · Lists, creates, selects, and edits profiles.
godot/src/UI/Menus/Characters/CharacterMenu.gd - Character Creator
godot/src/UI/Menus/Characters/CharacterCreator.gd - Color Editor
godot/src/UI/Menus/Characters/CharacterColorEditor.gd - Game World · Shared world lifecycle and scene.
godot/src/Main/GameWorld.gd - Players & Level · Local and remote characters inhabit the level.
godot/src/World/Characters/Player.gd - Chat & Notifications
godot/src/UI/ChatBox.gd
App Services
Process-wide Godot autoloads.
- Server Connection · Owns Nakama client, session, and socket connectivity.
godot/src/Autoload/ServerConnection.gd - Authenticator
godot/src/Autoload/Delegates/Authenticator.gd - Storage Worker
godot/src/Autoload/Delegates/StorageWorker.gd - Game Controls · Centralizes user and game control state.
godot/src/Autoload/GameControls.gd
Nakama Godot Addon
Vendored protocol integration.
- Nakama Client · Provides authenticated HTTP API access and sessions.
godot/addons/com.heroiclabs.nakama/client/NakamaClient.gd - HTTP Adapter
godot/addons/com.heroiclabs.nakama/client/NakamaHTTPAdapter.gd - Nakama Socket · Carries realtime gameplay and communication events.
godot/addons/com.heroiclabs.nakama/socket/NakamaSocket.gd - Storage Write Model · Serializes character storage-object writes.
godot/addons/com.heroiclabs.nakama/api/NakamaWriteStorageObject.gd
Nakama Backend
Local authoritative server runtime.
- Nakama Runtime · Authentication, storage, realtime services, and RPC host.
nakama/docker-compose.yml - World Lua Modules · Server extensions for synchronized world interactions.
nakama/modules/world_control.lua - CockroachDB · Persists Nakama server data.
nakama/docker-compose.yml
Tutorial Variant
Reduced self-contained learning path.
- Tutorial Godot Client
tutorial/godot/project.godot - Tutorial Nakama Stack
tutorial/nakama/docker-compose.yml
Connections 22
- Main Menu → Login & Registration: presents
- Main Menu → Character Management: routes to
- Main Menu → Game World: enters
- Login & Registration → Authenticator: authenticates through
- Character Management → Character Creator: creates profiles
- Character Creator → Color Editor: edits color
- Character Management → Storage Worker: loads and saves profiles
- Storage Worker → Storage Write Model: builds writes
- Authenticator → Server Connection: uses
- Storage Worker → Server Connection: uses
- Server Connection → Nakama Client: owns API client
- Server Connection → Nakama Socket: owns realtime socket
- Nakama Client → HTTP Adapter: sends API calls via
- Nakama Client → Nakama Runtime: HTTP API
- Nakama Socket → Nakama Runtime: WebSocket realtime
- Game World → Players & Level: hosts
- Game World → Game Controls: reads control state
- Players & Level → Nakama Socket: synchronizes movement
- Chat & Notifications → Nakama Socket: sends and receives events
- Nakama Runtime → World Lua Modules: loads
- Nakama Runtime → CockroachDB: persists data
- Tutorial Godot Client → Tutorial Nakama Stack: connects to