This repo has moved here!
This is a work in progress example of how to use Rivet with Unity and FishNet.
This is configured to use UDP sockets with the Tugboat transport. WebGL requires the Bayou transport, which is not included in this demo yet.
- Unity 2020.3 + Linux Dedicated Server build module
- Rivet CLI
Rivet's APIs are all available to test locally with fake data. This is useful for testing your game without having to deploy to Rivet.
- Run
rivet init
- You will need to create a new game if you haven't already
- Select
unity
engine type - Once complete, copy the token that looks like
dev_staging.XXXX
to your clipboard
- Paste this token under the API token
- Click play in the editor and click Find Lobby
Deploying the server
- Click File > Build Settings
- Select Dedicated Server from the list of platforms
- Click Build
- Create a folder named
build/LinuxServer
and save with the nameLinuxServer
. Click Save. - Run
rivet deploy -n prod
to deploy to production- You can now see your game servers running in the Rivet dashboard. These will automatically scale up and down based on player demand.
Connecting to the server
- Open the Rivet Hub
- Navigate to Your Game > API
- Under Production, click Create Public Token and click the copy button
- Paste this token under the Rivet Token field on the Rivet API game object. This token should look like
pub_prod.XXXX
. - Click play
- Install the following Unity assets
- FishNet
- Json.NET
- ParrelSync (optional, helps with testing multiple clients)
- Copy the following files
Assets/Scripts/RivetManager.cs
(provides API endpoints for Rivet and manages client/server state)Assets/Scripts/RivetAuthenticator.cs
(integrates Rivet's authentication with FishNet,automatically created byRivetManager
)
- Create a game object in your scene with the
RivetManager
component - Call
_rivetManager.FindLobby(...)
to connect to a lobby (seeRivetUI.cs
for example)