Crash Course

Networking
Fish-Net

This is configured to use UDP sockets with the Tugboat transport. WebGL requires the Bayou transport, which is not included in this demo yet.


Prerequisites

  • Unity 2020.3 + Linux Dedicated Server build module
  • Rivet CLI

Getting started

Testing Locally

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.

  1. 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
  2. Paste this token under the API token Update token
  3. Click play in the editor and click Find Lobby
    • You should see a lobby ID of 00000000-0000-0000-0000-000000000000 in the top left. This means you're testing against your local machine.
    • If this causes an error, you may need to navigate to File > Build Settings and switch to the Windows, Mac, Linux platform
    Running locally

Deploying to Rivet

Deploying the server

  1. Click File > Build Settings
  2. Select Dedicated Server from the list of platforms
    • Click the Switch Platform button if it's not selected already
    • Validate Target Platform is set to Linux
    Build settings
  3. Click Build
  4. Create a folder named build/LinuxServer and save with the name LinuxServer. Click Save.
    • Validate that you see a file located at build/LinuxServer/LinuxServer.x86_64
    Build folder
  5. 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

  1. Open the Rivet Hub
  2. Navigate to Your Game > API
  3. Under Production, click Create Public Token and click the copy button Create public token
  4. Paste this token under the Rivet Token field on the Rivet API game object. This token should look like pub_prod.XXXX.
  5. Click play

Importing in to your own project

  1. Install the following Unity assets
    • FishNet
    • Json.NET
    • ParrelSync (optional, helps with testing multiple clients)
  2. 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 by RivetManager)
  3. Create a game object in your scene with the RivetManager component
  4. Call _rivetManager.FindLobby(...) to connect to a lobby (see RivetUI.cs for example)

Was this page helpful?

Edit Page

Rivet

Open-source multiplayer infrastructure. Easy, flexible, and affordable.

This website is not sponsored by or affiliated with Unity Technologies or its affiliates. Unity Trademark(s) are trademark(s) or registered trademark(s) of Unity Technologies or its affiliates in the U.S. and elsewhere. | This website is not sponsored by, affiliated with, or endorsed by Epic Games, Inc. or its affiliates. 'Unreal Engine' is a trademark or registered trademark of Epic Games, Inc. in the U.S. and elsewhere. | The HTML5 Logo by the World Wide Web Consortium (W3C), used under a Creative Commons Attribution 3.0 License. Source | The Godot Engine Logo by the Andrea Calabró, used under a Creative Commons Attribution 4.0 International License. Source | Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries. Docker, Inc. and other parties may also have trademark rights in other terms used herein.

© 2024 Rivet Gaming, Inc. All rights reserved.