Multiplay Hosting support

Multiplayer Services sessions are compatible with Multiplay Hosting. The Multiplayer Services package provides out-of-the-box support for Multiplay Hosting's SQP query protocol.

The easiest way to allocate a server on Multiplay Hosting is to use and configure it through Unity Matchmaker, which automatically allocates the game server. Unity's Multiplayer Services package helps with configuring the required hooks in Multiplay Hosting.

The following code demonstrates how to start a session on the server:

var sessionManagerOptions = new MultiplaySessionManagerOptions()
{
    SessionOptions = new SessionOptions()
    {
        MaxPlayers = 10
    }
};

var sessionManager = await MultiplayerServerService.Instance.StartMultiplaySessionManagerAsync(sessionManagerOptions);

var session = sessionManager.Session;

Note: When using Matchmaker, even though the maximum number of players in a match is defined on the configuration, it is necessary to set it here, as well. Make sure that the maximum number of players defined here is at least as large as the one defined on the Matchmaker.

This code automatically creates a session for players to connect to when the server becomes allocated.

Refer to:

Authentication

See the Game Server Documentation here.

Server readiness

If Multiplay Hosting's Server readiness feature is enabled in the Build Configuration, it is possible to set the server as ready to receive player connections using the following code:

await sessionManager.SetPlayerReadinessAsync(true);

When using Matchmaker, if the feature is enabled, the player is only assigned to the server once the server is ready.

Backfilling

If the server was allocated with Matchmaker, it's possible to automatically request new players to join in order to backfill empty slots as a result of players leaving the session or because the match was created eagerly to minimize matchmaking time:

var sessionManagerOptions = new MultiplaySessionManagerOptions()
{
    SessionOptions = new SessionOptions()
    {
        MaxPlayers = 10
    }.WithBackfillingConfiguration(enable: true, autoStart: true)
};

This code starts the backfilling process as soon as Multiplay Hosting allocates the server (if the session is not full). Additionally, this code automatically starts the backfilling process when the session has one more more empty slots.

Note: If MaxPlayers defined here is not equal to the one in the matchmaking configuration, backfilling does not work as expected.

It is also possible to manually start and stop the backfilling process using the following code:

var sessionManager = await MultiplayerServerService.Instance. StartMultiplaySessionManagerAsync(sessionManagerOptions);
await sessionManager.Session.StartBackfillingAsync(); // Start the backfilling if it is not already in progress
await sessionManager.Session.StopBackfillingAsync(); /// Stop the backfilling

Starting and stopping the backfilling of a session can be useful if certain times are not appropriate for players to be joining (for example, if the session is about to end, or if a cinematic is in progress).

Refer to WithBackfillingConfiguration() for more information on the backfilling configuration.