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 Dashboard.
Note: Binding, and other interactions done through a Relay server, are handled using a networking solution such as UTP or NGO. NGO is higher level and uses UTP under the hood.
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.
Note: Before continuing, make sure you have a Unity Dashboard account. For more information see the UGS overview documentation.
Enable the Relay service.
- From the Unity Dashboard, select Multiplayer > Relay.
- Select Set up Relay.
- Continue to the Relay Setup guide embedded in the Unity Dashboard.
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 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 Simple Relay sample to learn how to interact with the sample project.
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.
Note: The Simple Relay sample only demonstrates what the standalone Relay SDK does, which doesn't include binding to a server. The standalone Relay SDK makes HTTP API calls to the Relay backend service to create allocations and join codes, and it doesn't affect the client’s network connections.
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 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.