pre-rivet
branch contains the source code of this project without Rivet implemented, in contrast to the main
branch. View these side by side to get a good picture of what it takes to integrate Rivet for your game.pre-rivet
,
then start by following the installation
instructions
on the plugin’s repo.
Once the plugin is installed in Godot, you’ll need to link your project with
Rivet by signing in. You can find the Rivet plugin in the same area as the
FileSystem
window in Godot.
Rivet panel missing?
Project > Reload Current Project
rivet.json
:
gamestate.gd
script.
Each code block below will replace part of a single function.
First, we’ll start with the ready function. We need to hook up the RivetHelper
autoloaded script to the local start_server
signal. This is so the plugin can
handle part of the multiplayer setup before our code does. We also need to call
setup_multiplayer
to initialize the multiplayer system.
Where did RivetHelper come from?
RivetHelper
, there is also Rivet
that
is autoloaded.rivet_print
function that is part of RivetHelper
. This makes it easier to
see logs that are about Rivet, and not about your game when you’re looking in
the hub.
Rivet.matchmaker.lobby.ready()
. This is a part of Rivet’s API, you can read
docs about all of the matchmaker endpoints.
This call will tell Rivet that the server is ready to accept players. Later,
we’ll call Rivet.matchmaker.lobby.setClosed()
to tell Rivet that the lobby is
closed and no more players can join.
How do I know which function to call?
Rivet.matchmaker.players.connected
would refer to this
endpoint.OK
, we’ll connect to the server using
the port
that was returned from the matchmaker.
What is response?
result
field, and we can check if it is equal to OK
.
Godot has a built-in OK
constant that is equal to 0
, so this is the same
as checking if response.result == 0
. If the result is OK
, then the body
field will contain the response body, and we can continue as expected.On the other hand, if the result is not OK
, then the body
field will
contain an error message. Above, we chose to crash the game if the result was
not OK
. This was because in this case it would be better for the game to
crash and for us to be able to see the error message in the logs, rather than
trying to continue. However, this might not be the best choice for your game.Dockerfile
:
Unfamiliar with Dockerfiles?
Dockerfiles
has one already written for youDockerfile
quicklyDockerfile
for you!What does this Dockerfile do?
godot:4.2
image that comes from Rivet’s GitHub registry. This
has been pre-built with export templates so that we don’t need to download
them every time.expect-dev
so that we can use unbuffer
to make sure that
the logs get flushed to stdout. This makes sure that even if the game
crashes, we’ll be able to see the logs.Where should I deploy to?
Staging
: Choose this namespace when you want to do a playtest of your
game. This is a good way to make sure that networking is working as
expected, to make sure a build works, or to try out a new feature with some
friends.Production
: Choose this namespace when you want to release a version of
your game. Deploying to this namespace won’t affect currently-running
lobbies, but will affect new lobbies that are created.