A multiplayer framework for Godot 4, built as a GDExtension.
It replaces Godot's
SceneMultiplayer
with NetwMultiplayer, which keeps its whole API. Existing @rpc,
MultiplayerSynchronizer and MultiplayerSpawner code works unchanged once
the addon is installed.
Download netwkd from the
latest release and
unzip it into your project's root. netwkd_steam, netwkd_discord and
netwkd_nakama are optional and unzip beside it.
Play them in the browser at netw-examples.pages.dev.
They come with the addon, under addons/netwkd/examples.
bomber, Godot's multiplayer bomber demoracing, Kenney's Starter Kit Racingrocket_league, cars and a ballfps, Kenney's Starter Kit FPSplayground, players pushing 900 cubes aroundmultiple_levels, players moving between levelswhiteboard, a shared drawing board
To run them from a clone of this repository, build the GDExtension before opening the project in Godot.
Configure a property once and write it normally. Every change reaches the other peers.
func _init() -> void:
Netw.configure_property(self, &"position").state() # the server writes it
Netw.configure_property(self, &"steering").input() # the controller writes it
Netw.configure_property(self, &"aim_angle").broadcast() # the controller sends it
Netw.configure_property(self, &"fuel") # sent when you askA property marked .state(), .input() or .broadcast() is sent every tick
it changes. Any other is sent with sync_property.
func refuel() -> void:
fuel = 100.0
Netw.sync_property(self, &"fuel")Smooth a property between updates.
Netw.configure_property(self, &"position").interpolate(
NetwInterpolate.new().lerp().smooth(0.05).to(&"position"))Send it in fewer bits.
Netw.configure_property(self, &"turret_yaw").broadcast().quantize(
NetwQuantizeAngle.new().bits(12).centered())Both work on a property a MultiplayerSynchronizer already replicates.
Configure the method, then call it. A node passed as an argument arrives as the receiver's own copy of that node.
func _init() -> void:
Netw.configure_rpc(self.apply_stun)
@rpc("authority", "reliable")
func apply_stun(attacker: Node) -> void:
play_stun(attacker)
Netw.rpc(target.apply_stun, attacker_root)Renaming or moving a node never breaks a call. A call that names a node the receiver has not spawned yet waits for the spawn.
Configure the signal, then emit it on every peer with one call.
func _init() -> void:
Netw.configure_signal(self.exploded)
Netw.emit(self.exploded, position)Configure a spawn function, then call it. Every peer builds the node, and the call returns this peer's copy for you to add.
func _init() -> void:
Netw.configure_spawn(make_bullet)
func make_bullet(direction: Vector2) -> Node:
var bullet := BulletScene.instantiate()
bullet.direction = direction
return bullet
muzzle.add_child(Netw.spawn(make_bullet, direction))Node.reparent is replicated.
player.reparent(arena.get_node(^"Spawns"))- Prediction and rollback. A controller runs its entity ahead and corrects when the server disagrees.
- Interest management. Each peer receives only the entities it can see.
- Persistence. Properties save and load with their entity, through a database you choose.
- Steam. Friends, invites, lobbies and parties, with Steam sign in.
- Discord. Presence, friends, parties with voice and Discord sign in.
- The lag compensation, prediction, and rollback architecture is based on netfox. Its documentation, documented issues, and Discord discussions were valuable references.
- Simulated network conditions on a real connection follow laggy-multiplayer-peer by Ricardo Nunes.
- The WebRTC signaler, transport, and related work are based on Tube.
- The wire architecture is based on yojimbo.
- Thanks to godot_debug_draw_3d for the approach the C# bindings use. The addon exports C function pointers and the generated C# calls through them.
- Multiplayer Game Programming. Architecting Networked Games by Joshua Glazer and Sanjay Madhav was insightful reading for general netcode architecture.