Get started
Install and set up Matchmaker and create your first matching ticket.
Read time 4 minutesLast updated 2 days ago
Important
Unity Matchmaker will support Multiplay Hosting until the deprecation date of March 31st, 2026. To aid your migration away from Multiplay Hosting, migration examples for alternative hosting providers are available. Matchmaker will continue to work with Relay and Distributed Authority after the Multiplay Hosting deprecation.
Warning
Attention: The Digital Services Act (DSA) requires Unity to notify our customers’ end users if Unity takes an action that impacts those end users under the DSA. To comply with this requirement, if you use Unity Gaming Services (UGS) products that rely on the Unity Authentication Service, you must integrate the notification API.For more information on DSA, refer to the Digital Services Act - compliance update.To make your game compliant, refer to DSA notifications.
Prerequisites
To get started with Matchmaker, you need to do the following:Configure your hosting
Before enabling Matchmaker, either initialize your chosen hosting solution, or a client-hosted solution provided by Unity. Refer to Get Started with Relay, and the Distributed Authority Quickstart for details about using these services with Matchmaker.Install the Multiplayer Services SDK
Access the Matchmaker services through the Multiplayer Services SDK. To install the latest Multiplayer Services SDK package for Unity follow these steps:- In the Unity Editor's Package Manager, select Unity Registry.
- Search for the following package: .
com.unity.services.multiplayer - Select the package and select Install. Refer to the Package Manager.
Important
If you use a version of Unity earlier than Unity 6, or Multiplayer Services earlier than 2.0, the recommended best practice is to upgrade to the latest version. If your game uses Multiplay Hosting for matchmaking, refer to Backward compatibility with Multiplay Hosting.
Set up Matchmaker
You can set up and manage Matchmaker through the Unity Dashboard:- In the Unity Dashboard, go to Development > Products.
- Select Matchmaker.
Create a queue and a pool
The next step in working with Matchmaker is to set up a queue and pool to control how Matchmaker groups and matches tickets. If you use a game hosting provider, you must use Cloud Code's allocation function to return allocation data from the hosting provider. Refer to Matchmaker hosting providers for more information. To create a queue and pool:- Select Queues > Create queue. Choose a name for the first queue and set the maximum number of players on a matchmaking ticket. Select Create.
-
Select the queue you just created, then in the Pools tab, select Create pool.
- Choose a name for the pool.
- Choose the queue that you created in the previous step.
- Select a Pool type.
- Set the timeout value for a ticket. Select Next.
-
Select your hosting type:
- If you're using a hosting provider, select Hosting via Cloud Code, then in the dropdown menu, select the Cloud Code Module Name that contains the allocation and poll functions for your hosting provider.
ImportantBefore using a hosting provider, refer to Matchmaker hosting providers to integrate Cloud Code modules to allocate game servers and coordinate matchmaking results.- If you're using a client-hosted solution provided by Unity, select Client Hosting.
- If you're migrating from Multiplay Hosting, select Multiplay Hosting (Deprecated). Refer to Backward compatibility with Multiplay Hosting.
- Select Next.
This creates matches of one team with a minimum of one player and a maximum of five players.{ "Name": "Test", "MatchDefinition": { "Teams": [ { "Name": "Main team", "TeamCount": { "Min": 1, "Max": 1 }, "PlayerCount": { "Min": 1, "Max": 5 } } ], "MatchRules": [] }, "BackfillEnabled": false}
- Select Logic Builder and set the Default QoS Region by selecting one the regions in the dropdown.
- Select Create at the bottom of the page.
Create a matchmaking ticket
Now that the matchmaker is configured, you can create and send a ticket to request a hosting allocation:Unity SDK
var players = new List<Unity.Services.Matchmaker.Models.Player>{ new ("Player1", new Dictionary<string, object>())};// Set options for matchmakingvar options = new CreateTicketOptions( "Default", // The name of the queue defined in the previous step, new Dictionary<string, object>());// Create ticketvar ticketResponse = await MatchmakerService.Instance.CreateTicketAsync(players, options);// Print the created ticket idDebug.Log(ticketResponse.Id);
CURL
# Fetch anonymous tokencurl -X POST -H "ProjectId: <projectId>" https://player-auth.services.api.unity.com/v1/authentication/anonymous# Call the create ticket endpointcurl -X POST -H "Authorization: Bearer <TOKEN>" \-H 'Content-Type: application/json' \--data-raw '{ "queueName": "Default", "attributes": {}, "players": [{ "id": "Player 1", "customData": {} }]}' \'https://matchmaker.services.api.unity.com/v2/tickets'
Note
Player Ids must be different to be matched together.
REST API
https://services.docs.unity.com/matchmaker/v2/index.html#tag/Tickets/operation/createTicketPoll ticket status
Once the ticket is created, the client polls to get the status of the ticket using the ticket ID returned when creating the ticket. When the ticket is assigned to a match and a server is allocated, Matchmaker adds the server information to the ticket status response. Starting in Multiplayer SDK 2.1.0, the assignment can be:- NoneAssignment for pending allocations.
- IpPortAssignment for IP/Port connections to the dedicated game server.
- MatchIdAssignment for Peer-to-Peer connections.
- MultiplayAssignment for Multiplay connections.
- CustomAssignment to manage custom connection info to the dedicated game server.
Unity SDK
MultiplayAssignment assignment = null;bool gotAssignment = false;do{ //Rate limit delay await Task.Delay(TimeSpan.FromSeconds(1f)); // Poll ticket var ticketStatus = await MatchmakerService.Instance.GetTicketAsync("<ticket id here>"); if (ticketStatus == null) { continue; } // Convert to platform assignment data (IOneOf conversion) if (ticketStatus.Type == typeof(MultiplayAssignment)) { assignment = ticketStatus.Value as MultiplayAssignment; } switch (assignment?.Status) { case MultiplayAssignment.StatusOptions.Found: gotAssignment = true; break; case MultiplayAssignment.StatusOptions.InProgress: //... break; case MultiplayAssignment.StatusOptions.Failed: gotAssignment = true; Debug.LogError("Failed to get ticket status. Error: " + assignment.Message); break; case MultiplayAssignment.StatusOptions.Timeout: gotAssignment = true; Debug.LogError("Failed to get ticket status. Ticket timed out."); break; default: throw new InvalidOperationException(); }} while (!gotAssignment);
CURL
# Call the poll ticket status endpoint with same anonymous token as for the creationcurl -X GET -H "Authorization: Bearer <TOKEN>" \--header 'Content-Type: application/json' \'https://matchmaker.services.api.unity.com/v2/tickets/status?id=<TICKETID>'