文档

​
​

Development

User Acquisition

Monetization

工业

Multiplayer Services SDK

All Services

Multiplayer Services SDK

此页面不支持所选语言。
Multiplayer
​
​
Multiplayer Services SDK
  • Overview
  • Get started
  • Use multiplayer sessions
    • Integrate Multiplayer sessions
      • Initialize UGS and authenticate the player
      • Create a session
      • Create sessions in the Editor
      • Find and join a session
      • Matchmaking
        • Match make with the Quick Join API
        • Advanced matchmaking
      • Migrate session host
      • Leave a session
      • Get a list of joined sessions
      • Delete a session
      • Session configuration options
    • Game server hosting support
  • Manage sessions
  • Connect players through a relay
  • Networking
  • Matchmaking
  • Monitor and debug sessions
  • Tutorials
  • Reference
  1. Multiplayer Services SDK

Advanced matchmaking

Use additional rules and parameters to matchmake players on multiple variables.
阅读时间2 分钟
最后更新于 16 天前

Find a session using Unity Matchmaker service

Use the Unity Matchmaker service to have a player join the best-suited session using more advanced rules.
Matches can be tuned for network quality using Quality of Service (QoS) rules on the pool configuration. This type of rule ensures that players in the match don't exceed a specified latency to the host or server. For a given match, these rules also select the most suitable region in which to allocate a server or relay.
注意
The Multiplayer Services SDK automatically performs QoS measurements, and includes the results with the matchmaking request.
The following example demonstrates how to find and join a session using Matchmaker:
var matchmakerOptions = new MatchmakerOptions{ QueueName = "Friendly"};var sessionOptions = new SessionOptions(){ MaxPlayers = 2}.WithDirectNetwork();var matchmakerCancellationSource = new CancellationTokenSource();ISession session = await MultiplayerService.Instance.MatchmakeSessionAsync(matchmakerOptions, sessionOptions, matchmakerCancellationSource.Token);
For Matchmaker to find a session for the player, the user is expected to configure the matchmaking rules.
注意
To test this code, create a queue named
Friendly
and use the default pool.

Network choice when matchmaking

  • The recommended best practice is to use
    WithDirectNetwork()
    when the Matchmaker pool is configured with your preferred hosting provider.
  • WithDirectNetwork()
    instructs clients to use direct network connections to the allocated server's IP and port.
  • The recommended best practice is to use
    WithRelayNetwork()
    or
    WithDistributedAuthorityNetwork()
    when the Matchmaker pool is configured for client-hosted (peer-to-peer) games.

Cancel matchmaking

If the player wants to stop the matchmaking process, use the following code:
matchmakerCancellationSource.Cancel();
This indicates to the Multiplayer Services SDK to delete the matchmaking ticket that was sent in the background to the service, and stop the search for a session.

Matchmaking results

The session also provides access to the Matchmaking Results with the information about the match and the players that are going to connect to the session (their teams and their data).
Some information, such as team breakdown and custom ticket data, is only available through matchmaking results. The results also include the list of expected players, which is handy as it's available immediately and authoritatively before the players join the session and connect.
You can access the matchmaking results with the following code:
var matchmakingResults = session.GetMatchmakingResults();

Additional resources

  • ISession interface
  • MatchmakerOptions
  • Matchmaker rule samples
  • QuickJoinOptions

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • Find a session using Unity Matchmaker service

      • Network choice when matchmaking

      • Cancel matchmaking

      • Matchmaking results

    • Additional resources


报告此页面的问题