Course contentsShow
← Unity Game Development
Lesson 808 of 82812. Multiplayer and DeploymentFree lesson

Automating Matchmaking with Unity Game Services

Define matchmaking queues and rules to automatically group players based on skill levels, latency, or game preferences.

In this lesson, you will learn how to configure matchmaking queues and rules in Unity Game Services to automate the grouping of players based on skill levels and latency.

The Logic of Matchmaking Rulesets

While a Lobby system allows players to manually gather, Matchmaking acts as an automated "invisible hand" that connects players across different lobby instances based on predefined criteria. In the Unity Matchmaking dashboard, you define a Queue—the waiting area—and a Ruleset—the logic that determines who belongs together.

Defining Rules for Fair Play

A ruleset is essentially a collection of constraints that must be satisfied before a match can start. Two common types of rules are:

  1. Skill-Based Rules: You can utilize a Player Skill attribute. The Matchmaking service calculates the distance between players’ ratings (e.g., ELO). You can set an "expansion" rule where the allowed skill gap increases the longer a player waits in the queue, ensuring they eventually find a match rather than waiting indefinitely.
  2. Latency-Based Rules: By using the player's reported region or latency (often integrated via Relay or dedicated server ping data), you can create a rule that restricts grouping to players within the same geographical "bucket" to minimize lag.

Implementation Concept

Once your queue is configured in the Unity Dashboard, your client code doesn't need to write complex sorting algorithms. Instead, you interact with the MatchmakerService:

// Example: Creating a ticket for the automated queue
CreateTicketOptions options = new CreateTicketOptions("DefaultQueue", new Dictionary<string, object> {
    { "skill", 1500 }, // Player's stored skill rating
    { "region", "us-east" }
});

var ticket = await MatchmakerService.Instance.CreateTicketAsync(new List<Player> { player }, options);

When the Matchmaking service finds players that satisfy your rules, it triggers a "backfill" or a "match found" event. Your game client or server then receives the connection details (often a Relay join code or a server IP) to transition the players from the queue directly into an active game session. By automating these constraints, you ensure that every session maintains a high standard of parity and performance without manual intervention.

Key Takeaway: Matchmaking queues use programmable rulesets to automatically pair players based on skill or latency, ensuring balanced matches while offloading the logic from the client to Unity Game Services.