This guide will walk you through creating and deploying a multiplayer game with
Godot 4.2.If you are using Godot 4.1/4.0/3.x, please be aware that some details may be different.
Godot provides great multiplayer capabilities out of the box. We’ll be using
Godot’s built-in networking along with Rivet’s Godot plugin to build a
server-authoritative multiplayer game on top of Rivet.Godot supports ENet, WebSocket, and WebRTC transports. We’ll be using ENet for
this tutorial, but it’s easy to swap out.
The setup_multiplayer() call will do a check to properly start a Godot. Add this code wherever the server is started. This function name needs to
match
the one used in the RivetHelper.start_server.connect call above.
In the Rivet plugin, we can go to the deploy tab, and select “Staging” from the
dropdown. Then, click “Build & Deploy”. This will build the Dockerfile we just
created, and upload the Docker image to Rivet’s servers.
Now that we’ve deployed the game to Rivet, we can build a game client that will
be able to connect to Rivet. First, we need to specify which server we want to
connect from the “Playtest” tab. To use the settings that we deployed the server
with above, we need to select “Rivet servers”, and set the namespace to
“Staging”.Note that changing anything under the “Playtest” tab will require
rebuilding or restarting the game, since the tokens are only set when the game
is starting. This is also something to verify when shipping builds, you don’t
want to upload a version to Steam that tries to connect to your Staging server!To build the client we can either build through Godot’s export system, or simply
run the game from the editor. Both are configured to get the tokens needed for
the namespace you have set. You don’t need to change anything with how you would
export the game normally for this to work!