gdDocumentation0.8.0

English | 日本語

Godot Online: the short guide

Only what you need to start. The full reference is full reference.

The shape of a world

Node2D
└── Online          ← the Online-side world. Its script holds the Online-side code
    ├── Secret      ← runs only on the Online side: settings, sign-in, keys
    └── Paddle_7    ← a node placed by spawn() with an owner

Build one

1. The world. Make one scene whose root is Online, attach a script, add a Secret child. Put the player scene into player_scene on Secret and every player who joins gets one.

extends Online

func _on_player_joining(my):   # _on_<signal> connects itself, like _ready
	print(my.name, " joined")

2. The player. Any root type. With at least one @online in the script, a Node2D/Node3D shares its position and rotation without a mark.

extends CharacterBody2D

@online var color := Color.WHITE    # shared with everyone
@online_input var axis := 0.0       # written on the owner's device, read on the Online side

func _process(_delta):              # unmarked code runs on every device
	axis = Input.get_axis("ui_left", "ui_right")

@online                             # runs on the Online side only
func _physics_process(_delta):
	velocity.x = clampf(axis, -1.0, 1.0) * 220.0
	move_and_slide()

3. Run the Online side once. It creates the keys and prints where the certificate is. Copy that certificate.pem into the project as res://online-ca.pem.

godot --headless --path . -- --online-server

4. Play. With the Online side running, run the project as usual and it connects as a client.

The names

KindNames
Marks@online @online_my @online_save @online_save_my @online_input, and @online("auto_off") to stop sharing the position
TypesOnline Secret
Functionspawn(scene, my, properties) (arguments are read by type; all optional)
Wordsmy (the owner: my.id my.guest my.name), world (the Online this node lives in)
Online signalsplayer_joining(my) player_left(my) logged_in(my) login_failed(reason) spawned(node). Write _on_<name> and it connects
Signal on every nodedisconnected
External accountOnline.login_with("provider") Online.logout(); configure the provider in Secret before use
MarkWho receives itSaved
@online var hpeveryoneno
@online_my var handthe owner and the Online sideno
@online_save var leveleveryoneyes (Redis)
@online_save_my var coinsthe owner and the Online sideyes
@online_input var axiswritten on the owner's device, read on the Online sideno

I want to

I want toWrite
Put a node in the worldspawn(BULLET) on the Online side, spawn(BULLET, my) for a player's own
Jump or shoot (an event)@online func jump(), called from the device
Hold a key (a state)@online_input var axis, written in _process
Show an Online-side value in a Label@online($Score.text) var score := 0
Keep a value across restarts@online_save var level := 1 and redis_host on Secret
Room size, reconnect graceroom_max and keep_sec on Secret
Reach a server on another machineroom_host on Secret
Try it locallyProject ▸ Tools ▸ "Online: Start the local test container" (needs Docker)

When something goes wrong

MessageDo
Cannot read the CA certificateCopy the certificate from the path the server printed
Cannot reach the roomStart the Online side first
The room is fullRaise room_max. Not an error. The client retries every 5 s and gets in when a seat frees
Too many new players from this address8 new accounts per address per 10 minutes. Existing accounts still sign in
... is decided by the Online sideYou wrote an @online value on a client. Move that line into @online func
Signed in from another deviceThe same account signed in elsewhere, so this copy stopped. Start it again to take the account back
The save store is not reachableRedis is down on the Online side. The client retries by itself
this is a client build--online-server needs the editor or server build
The other player dropsTwo copies share a project name. Rename one
Section of full referenceWhat it covers
Annotationswhich types sync, where saves go, annotations on signals and functions
Where code runsordinary vs annotated code, event-only sync
SecretServer-side-only code and the 19 inspector settings
LoginGuest accounts and optional external account linking
Running a server / Matchmaking / Player-hosted worldsdedicated server, matchmaking, players hosting rooms
Fine tuningrates, smoothing, prediction. Works without any of it
Distribution boundarieswhat never enters a Client PCK

The examples in samples/ are pong and shobon_jump.