Get started with Relay
Read the following sections to learn how to set up a Relay project and how to use the Relay sample project. If you haven’t already, visit Get started with UGS to learn how to work with the Unity Cloud Dashboard.
Set up a Relay project
Relay is a PAYG (pay as you go) service with a free tier. If you exceed the free tier monthly usage limit, you must enter payment information to keep full access to Relay and any other services. For more information, check out Sign up for UGS.
To get started with Relay, you need to do the following:
Set up Relay
You can set up and manage Relay through the Unity Cloud Dashboard:
- Go to cloud.unity.com.
- Select the Products tab from the sidebar.
- Under Gaming Services > Multiplayer, go to Relay and select Launch.
When you launch Relay for the first time, this adds Relay to the Shortcuts section on the sidebar and opens the Overview page.
Link your Relay project in the Unity Editor
- Open your project in the Unity Engine and navigate to Edit > Project Settings.
- From the Project Settings window, go to the Services tab.
- Select Use an existing Unity project ID and link to the Unity Cloud Dashboard project displayed in the Setup guide.
- After you the project links successfully, you're ready to move on to the next step of the integration process.
Install the Relay package
- In Unity, navigate to Window > Package Manager.
- From the Package Manager, search or scroll to find the “Relay” package within the Unity Registry.
- Select the package and click the Install button.
Check out the Simple Relay sample to learn how to interact with the sample project.
Relay with Netcode for Game Objects
Using Relay with Netcode for GameObjects is a simple use case. Check out Relay with Netcode for GameObjects to learn more.
Simple Relay sample
The Simple Relay sample is an example project that exercises the Relay SDK. The project provides a simple user interface (UI) with buttons, and is intended for manual testing of the SDK. To try the sample project, follow the steps below.
Import the Simple Relay sample project
Open a Relay project with the Unity Editor (version 2020.3). If you don’t have a Relay project set up yet, check out Set up a Relay project.
Open the Package Manager and navigate to the Relay package.
Expand the Samples section.
Select Import to import the Simple Relay sample project.
Now that you have imported the Simple Relay sample project, you can open it as a scene. It's located within the current project under
Assets/Samples/Relay/1.0.1-pre.3/Simple Relay Sample.
Select File > Open Scene.
Navigate to the Simple Relay sample scene.
Continue onto Use the Simple Relay sample to learn how to use it.
Use the Simple Relay sample
Sign into the Unity Editor.
Go to Account > Sign in…
Selecting the Sign in button opens the Unity Cloud Dashboard in a browser window. Make sure you’re signed into the same account with the Relay-enabled project.
Link a project to the Simple Relay sample.
Select Edit > Project Settings…
Select Use an existing Unity project ID.
Select the organization and the project.
Select Link project ID.
If successful, your project ID appears under Unity Project ID.
Start the Simple Relay sample
Select the Play button to start the sample.
Go through and select each of the buttons within the sample in order:
- Sign In (Anonymously) uses Unity’s Anonymous authentication to sign into Relay. This generates a player ID.
- Get Regions lists all the regions in which a Relay server is available.
- Create Relay creates a Relay allocation and returns the host allocation ID.
- Get Join Code generates a join code for the host to share with other players.
- Join Relay joins the Relay allocation and returns a player allocation ID.