Skip to main content

Add dedicated server button - Quick match with dedicated servers - (Unity module)

Last updated on November 25, 2024

What's on the menu

You will learn to implement matchmaking using the dedicated server (DS) type in this tutorial.

For matchmaking using a dedicated server architecture, a Unity user interface (UI) has been prepared for you. It is available in the Resources section and consists of the following files:

  • MatchmakingSessionDSHandler_Starter.cs: A C# script that contains most of the dedicated server matchmaking implementation. This class connects the UI and the AccelByte Gaming Services (AGS) Game SDK service wrapper class to call its API.
    • CS file: Assets/Resources/Modules/MatchmakingSessionDS/Scripts/UI/MatchmakingSessionDSHandler_Starter.cs
  • MatchmakingSessionDS_Starter.prefab: The prefab file that you will use to implement dedicated server matchmaking. The Dedicated Server button is autogenerated and will call ClickDedicatedServerButton in MatchmakingSessionDSHandler_Starter.cs.
    • Prefab file: Assets/Resources/Modules/MatchmakingSessionDS/Prefabs/UI/MatchmakingSessionDS_Starter.prefab

Take a look at the UI states in more detail below.

Select game mode state

This UI state will be displayed when the player accesses the Play Online > Quick Play menu from the main menu. It displays buttons to select the game mode before matchmaking. There are two game modes: Elimination and Team Deathmatch.

  • MatchmakingSessionHandler.cs: This script is designed to handle UI functions related to selecting a match type for creating a match session. It features a Button UI element and logic to process the selected server type.
    • CS file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionHandler.cs
  • MatchmakingSessionMenuCanvas.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
    • Prefab file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionMenuCanvas.prefab

Select game mode state in Unity Byte Wars with quick DS match

Select server type state

This state will be displayed after the player selects the preferred game mode. It displays buttons to select a server type for the matchmaking. By default, this state contains an empty container. On runtime, however, the MatchmakingSessionDS_Starter.prefab will be automatically generated to show the dedicated server type button option.

  • MatchmakingSessionServerTypeSelection.cs: This script is designed to handle UI functions related to selecting a server type for creating a match session. It features a Button UI element and logic to process the selected server type.
    • CS file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionServerTypeSelection.cs
  • MatchmakingSessionServerTypeSelection.prefab: A GameObject prefab that is created based on the Canvas Panel UI GameObject.
    • Prefab file: Assets/Resources/Modules/MatchmakingSession/MatchmakingSessionServerTypeSelection.prefab

Preview of select server type state Unity Byte Wars quick match dedicated server

Ready the UI

You will learn how to implement UI functionality before calling the AGS Game SDK API for dedicated server matchmaking.

  1. Open MatchmakingSessionDSHandler_Starter. You will implement matchmaking with the Elimination game mode using dedicated server as the server type. Modify ClickDedicatedServerButton method as shown below.

    public void ClickDedicatedServerButton()
    {
    BytewarsLogger.Log("Dedicated server matchmaking is not implemented yet");
    }
  2. In the Unity Editor, open Assets/Resources/Modules/MatchmakingSessionDS/MatchmakingWithDSAssetConfig.asset and enable Is Starter Active in the Inspector. This will switch the script that's handling the UI from to MatchmakingSessionDSHandler_Starter.

  3. Play the game in the Editor. If your implementation was successful, you will be able to navigate to the server selection panel and see the following log when you click DEDICATED SERVER:

    [MatchmakingSessionDSHandler_Starter.cs] [ClickDedicatedServerButton] [Log] [14] - Dedicated server matchmaking is not implemented yet

Resources