Skip to content

Integrating Unity Matchmaker

Unity Matchmaker is part of Unity Gaming Services (UGS). It handles player ticket submission, queue management, and match rules — but it needs an external allocator to actually start a dedicated server.

Gameye provides a Cloud Code module — GameyeAllocator — that bridges Unity Matchmaker to the Gameye Session API. When a match is formed, Matchmaker calls the allocator, Gameye starts a dedicated server, and connection details are passed back to your game clients. No polling, no retry loops.

Game Client → Unity Matchmaker → Cloud Code (GameyeAllocator)
Gameye API (POST /session)
↓ ~0.5s
Dedicated game server
Game Client ← Unity Matchmaker (IP + port delivered)

Gameye’s POST /session returns the server IP and port synchronously on the allocation call. The Poll function is implemented for compatibility with Unity’s two-phase Allocate/Poll contract — it resolves immediately on the first call in almost all cases.

Before setting up the allocator, make sure you have:

Terminal window
npm install -g @unity-services/ugs-cli

The GameyeAllocator module is available as open source from Unity’s matchmaker-hosting-providers repository. Clone or download the repo, then work from the modules/GameyeAllocator/ directory:

Terminal window
git clone https://github.com/Unity-Technologies/matchmaker-hosting-providers.git
cd matchmaker-hosting-providers/modules/GameyeAllocator

If you’d prefer Gameye to deploy and configure the module for you as part of onboarding, contact [email protected] or reach out on Discord.

The module contains:

modules/GameyeAllocator/
├── GameyeAllocator.sln
├── CONFIGURATION.md
└── Project/
├── GameyeAllocator.cs ← Allocate + Poll logic
├── GameyeAllocatorConfig.cs ← Edit this to configure the allocator
├── GameyeAllocator.csproj
└── Client/
├── GameyeClient.cs
└── Models/
├── SessionRequest.cs
└── SessionResponse.cs

Open Project/GameyeAllocator.cs and edit the GameyeAllocatorConfig block in ModuleConfig.Setup():

config.Dependencies.AddSingleton(new GameyeAllocatorConfig
{
// Required — the application image name registered in the Gameye Admin Panel.
ImageName = "MyGame",
// The API environment. Use Sandbox for development, Production for live.
Environment = GameyeEnvironment.Production,
// Default deployment region — used when no region mapping matches.
DefaultLocation = "eu-west",
// Primary game server port (must match your Dockerfile EXPOSE / Admin Panel config).
GamePort = 7777,
});
FieldWhere to find the value
ImageNameGameye Admin Panel → Applications — must match exactly
EnvironmentSandbox for development, Production for live
DefaultLocationSee available locations
GamePortMust match the port exposed in your Dockerfile

The allocator reads your API token from Unity’s Secret Manager at runtime — it is never hardcoded.

  1. Go to Unity Dashboard → your project → Administration → Secrets
  2. Click Add Secret
  3. Set the name to GAMEYE_API_TOKEN
  4. Set the value to your Gameye API bearer token (create or retrieve it in the Admin Panel)

Authenticate with Unity and deploy:

Terminal window
# Log in to UGS
ugs login
# Link to your Unity project (follow the prompts for Project ID and environment)
ugs init
# Deploy the module
cd modules/GameyeAllocator
ugs deploy

Deployment typically takes under a minute. You’ll see a confirmation in the terminal when the module is live.

  1. Go to Unity Dashboard → Matchmaker → Queues
  2. Select your queue (or create one)
  3. Open the Pools tab and create or edit a pool
  4. Set Hosting Type to Cloud Code
  5. Fill in the allocator function names:
FieldValue
Module NameGameyeAllocator
Allocate Function NameMatchmaker_AllocateServer
Poll Function NameMatchmaker_PollAllocation
  1. Save the pool

Start a matchmaking request from your game client. When a match is formed:

  • Matchmaker calls Matchmaker_AllocateServer
  • Gameye provisions a dedicated server (~0.5 seconds)
  • Matchmaker calls Matchmaker_PollAllocation — connection data is returned immediately
  • Your game clients receive the server IP and port

Debugging: Cloud Code logs are available at Unity Dashboard → Cloud Code → Logs. Each allocator invocation logs the resolved region and the Gameye API response — check here first if allocations are failing.

The allocator supports two approaches to region routing, evaluated in priority order:

Section titled “Option A — Unity QoS automatic region selection (recommended)”

Unity Matchmaker runs QoS measurements to determine the lowest-latency region for each group of matched players and writes the result to MatchProperties["Region"]. The allocator reads this value and maps it to a Gameye location using LocationByRegion.

This approach requires no per-region pools — a single global pool can serve all regions.

config.Dependencies.AddSingleton(new GameyeAllocatorConfig
{
ImageName = "MyGame",
Environment = GameyeEnvironment.Production,
DefaultLocation = "eu-west",
GamePort = 7777,
LocationByRegion = new Dictionary<string, string>
{
{ "eu-west", "eu-west" },
{ "us-central", "us-central" },
{ "asia-northeast", "asia-northeast" },
},
});

On first run, check Cloud Code logs to confirm the exact value Unity writes for your QoS regions — it may be a human-readable name or a UUID depending on your Matchmaker configuration. If the value has no entry in LocationByRegion, the allocator logs a warning and falls through to the next step.

If Unity QoS is not configured, or as a fallback when LocationByRegion has no match, the allocator maps the matched pool’s name to a Gameye location using LocationByPool.

This requires one pool per region in your Matchmaker queue, with QoS rules routing players to the correct pool before matching.

LocationByPool = new Dictionary<string, string>
{
{ "eu-west-pool", "eu-west" },
{ "us-central-pool", "us-central" },
{ "ap-ne-pool", "asia-northeast" },
},

Pools not in the map fall back to DefaultLocation.

PrioritySourceConfig property
1MatchProperties["Region"] (Unity QoS)LocationByRegion
2Pool nameLocationByPool
3Static fallbackDefaultLocation

Reference: Unity region → Gameye location

Section titled “Reference: Unity region → Gameye location”
Unity QoS regionGameye location
us-eastus-east
us-westus-west
eu-westeurope
eu-centraleurope
asia-eastasia-southeast
asia-southeastasia-southeast
southamerica-eastsouthamerica
australia-southeastaustralia

For the full list of Gameye location IDs, see Available Locations.

By default, Gameye starts sessions using the highest-priority image tag configured in the Admin Panel. To pin a specific tag:

Version = "v1.2.3",

If your game server exposes more than one port (e.g. a query port or RCON), list them in AdditionalPorts. They are returned in the match assignment data alongside the primary port so game clients can access them.

AdditionalPorts = new Dictionary<string, int>
{
{ "query", 27015 },
{ "rcon", 27020 },
},

The primary port is available to clients as port. Additional ports appear as port_query, port_rcon, etc.

If a warm pool is configured for the region and image, Gameye returns an already-running server instantly — sub-second allocation. In this case, env values set in the allocator code are ignored; configure any required environment at the warm pool level instead.