You can create an allocator other than the examples listed here. An allocator is a Cloud Code module with two required pieces: a ModuleConfig class for dependency registration, and the allocator class itself implementing IMatchmakerAllocator.
The allocator must implement exactly two methods, both decorated with [CloudCodeFunction] using these exact names:
public class MyAllocator : IMatchmakerAllocator
{
[CloudCodeFunction("Matchmaker_AllocateServer")]
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request) { ... }
[CloudCodeFunction("Matchmaker_PollAllocation")]
public async Task<PollResponse> Poll(IExecutionContext context, PollRequest request) { ... }
}The function names Matchmaker_AllocateServer and Matchmaker_PollAllocation must match exactly — these are what you enter in the pool's Hosting Settings in the dashboard.
What is the Allocate / Poll pattern and why does it exist?
Most providers don't return a ready server IP immediately — allocation is asynchronous. Allocate fires the request to your provider and returns straight away. Matchmaker then calls Poll on a timer until your allocator signals the server is ready. This avoids a single long-running function call that would time out.
The practical implication: anything you need in Poll must be stored in AllocationData during Allocate. Matchmaker persists it and hands it back to you on every Poll call.
// In Allocate — fire request, store tracking data
var sessionId = await myProvider.RequestServerAsync(...);
return new AllocateResponse(AllocateStatus.Created)
{
AllocationData = new Dictionary<string, object>
{
{ "sessionId", sessionId },
{ "region", region }
}
};
// In Poll — retrieve tracking data, check status
var sessionId = request.AllocationData["sessionId"].ToString();
var status = await myProvider.GetServerStatusAsync(sessionId);
if (status.IsReady)
return new PollResponse(PollStatus.Allocated)
{
AssignmentData = AssignmentData.IpPort(status.Ip, status.Port)
};
return new PollResponse(PollStatus.Pending);What return statuses are available when I poll and when should I use each?
| Method | Status | When to use |
|---|---|---|
| Allocate | AllocateStatus.Created | Request sent successfully — Matchmaker will begin polling |
| Allocate | AllocateStatus.Error | Request could not be made — Matchmaker fails the ticket immediately |
| Poll | PollStatus.Pending | Server not ready — Matchmaker will call Poll again |
| Poll | PollStatus.Allocated | Server ready — must include AssignmentData |
| Poll | PollStatus.Error | Allocation failed or timed out — Matchmaker fails the ticket |
What is ModuleConfig and is it required?
Yes. In Cloud Code it is the entry point for Unity's dependency injection and must be present. Register every service your allocator's constructor depends on here. If a dependency is missing from ModuleConfig, the module will throw at runtime when Matchmaker tries to instantiate it.
public class ModuleConfig : ICloudCodeSetup
{
public void Setup(ICloudCodeConfig config)
{
config.Dependencies.AddSingleton(GameApiClient.Create()); // required for Secret Manager
config.Dependencies.AddScoped<IMyProviderFactory, MyProviderFactory>();
}
}Your allocator class receives its dependencies through constructor injection:
public class MyAllocator(IGameApiClient gameApiClient, IMyProviderFactory providerFactory) : IMatchmakerAllocator